Do not generate unnecessary super-call checks for functions with defaults
Such check should only be generated for a function in an open class #KT-11962 Fixed
This commit is contained in:
@@ -3,25 +3,25 @@
|
||||
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun def(i: Int = 0): Int {
|
||||
return i;
|
||||
open class MyClass {
|
||||
fun def(i: Int = 0): Int {
|
||||
return i
|
||||
}
|
||||
}
|
||||
|
||||
fun box():String {
|
||||
val clazz = Class.forName("SuperCallCheckKt")
|
||||
|
||||
val method = clazz.getMethod("def\$default", Int::class.java, Int::class.java, Any::class.java)
|
||||
val result = method.invoke(null, -1, 1, null)
|
||||
val method = MyClass::class.java.getMethod("def\$default", MyClass::class.java, Int::class.java, Int::class.java, Any::class.java)
|
||||
val result = method.invoke(null, MyClass(), -1, 1, null)
|
||||
|
||||
if (result != 0) return "fail 1: $result"
|
||||
|
||||
var failed = false
|
||||
try {
|
||||
method.invoke(null, -1, 1, "fail")
|
||||
} catch(e: Exception) {
|
||||
method.invoke(null, MyClass(), -1, 1, "fail")
|
||||
}
|
||||
catch(e: Exception) {
|
||||
val cause = e.cause
|
||||
if (cause is java.lang.UnsupportedOperationException &&
|
||||
cause.message!!.startsWith("Super calls")) {
|
||||
if (cause is UnsupportedOperationException && cause.message!!.startsWith("Super calls")) {
|
||||
failed = true
|
||||
}
|
||||
}
|
||||
|
||||
+4
-3
@@ -8,6 +8,7 @@ class A {
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
// Test argument reordering when call site argument order differs from declaration one: 18 + 1 for super call check
|
||||
// 13 LOAD
|
||||
// 5 STORE
|
||||
|
||||
// Test argument reordering when call site argument order differs from declaration one
|
||||
// 12 LOAD
|
||||
// 5 STORE
|
||||
|
||||
+4
-3
@@ -7,6 +7,7 @@ class A {
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
// Test there is no argument reordering when call site argument order same as declaration one: 15 + 1 for super call check
|
||||
// 10 LOAD
|
||||
// 2 STORE
|
||||
|
||||
// Test there is no argument reordering when call site argument order same as declaration one
|
||||
// 9 LOAD
|
||||
// 2 STORE
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
// KT-11962 Super call with default parameters check is generated for top-level function
|
||||
|
||||
fun foo(x: Int = 1) { }
|
||||
|
||||
class FinalClass {
|
||||
fun bar(x: Int = 2) { }
|
||||
}
|
||||
|
||||
object Object {
|
||||
fun baz(x: Int = 3) { }
|
||||
}
|
||||
|
||||
fun test() {
|
||||
fun local(x: Int = 4) { }
|
||||
}
|
||||
|
||||
// 0 ATHROW
|
||||
@@ -1,13 +0,0 @@
|
||||
inline fun test(a: Int = 1, b: Long = 1L, c: String = "123") {
|
||||
val d = 1
|
||||
}
|
||||
|
||||
//
|
||||
// 1 test\$default\(IJLjava/lang/String;ILjava/lang/Object;\)V\s+L0
|
||||
// 1 LOCALVARIABLE a I L0 L8 0
|
||||
// 1 LOCALVARIABLE b J L0 L8 1
|
||||
// 1 LOCALVARIABLE c Ljava/lang/String; L0 L8 3
|
||||
// 1 LOCALVARIABLE \$i\$f\$test I L5 L8 4
|
||||
// 1 LOCALVARIABLE d I L7 L8 5
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
class A {
|
||||
open class A {
|
||||
inline fun test(a: Int = 1, b: Long = 1L, c: String = "123") {
|
||||
val d = 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user