Fix KotlinReflectionInternalError on invoking callBy with defaults in supertypes
There are two parts in this change: 1) Previously, we looked up $default methods with the incorrect signature in supertypes. For example in defaultInSuperClass.kt, we'd try to find a method foo$default with the signature `(B, String, String, int, Object)` in the class A. Now we're modifying the array of parameter types on each step if we're looking for a static $default method, by assigning its first element to be the containing class. This fixes cases when defaults come from a superclass. 2) For interfaces, $default methods are actually located in the corresponding DefaultImpls class. Now we look up that class and search for the $default method there. Note that this is needed because of KT-33430. This fixes cases when defaults come from a superinterface. #KT-13936 Fixed
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
// IGNORE_BACKEND: JS_IR, JS, NATIVE
|
||||
// WITH_REFLECT
|
||||
|
||||
open class A {
|
||||
open fun foo(a: String, b: String = "b") = b + a
|
||||
}
|
||||
|
||||
class B : A() {
|
||||
override fun foo(a: String, b: String) = a + b
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val f = B::foo
|
||||
|
||||
assert("ab" == f.callBy(mapOf(
|
||||
f.parameters.first() to B(),
|
||||
f.parameters.single { it.name == "a" } to "a"
|
||||
)))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// IGNORE_BACKEND: JS_IR, JS, NATIVE
|
||||
// WITH_REFLECT
|
||||
|
||||
interface A1 {
|
||||
fun test(o: String, k: String): String
|
||||
}
|
||||
interface A2 : A1
|
||||
|
||||
interface B1 {
|
||||
fun test(o: String = "O", k: String = "K"): String
|
||||
}
|
||||
interface B2 : B1
|
||||
|
||||
interface C1
|
||||
interface C2 : C1
|
||||
|
||||
interface D
|
||||
interface E : A2, B2, C2 {
|
||||
override fun test(o: String, k: String): String {
|
||||
return o + k
|
||||
}
|
||||
}
|
||||
|
||||
class Z : D, E
|
||||
|
||||
fun box(): String {
|
||||
val f = Z::test
|
||||
return f.callBy(mapOf(f.parameters.first() to Z()))
|
||||
}
|
||||
Reference in New Issue
Block a user