Fix for KT-7557: NoSuchMethodError when capturing receiver in object expression
#KT-7557 Fixed #KT-7769 Fixed
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
interface B<T> {
|
||||
val bar: T
|
||||
}
|
||||
|
||||
fun String.foo() = object : B<String> {
|
||||
override val bar: String = length().toString()
|
||||
}
|
||||
|
||||
class C {
|
||||
|
||||
fun String.extension() = this.length()
|
||||
|
||||
fun String.fooInClass() = object : B<String> {
|
||||
override val bar: String = extension().toString()
|
||||
}
|
||||
|
||||
fun String.fooInClassNoReceiver() = object : B<String> {
|
||||
override val bar: String = "123".extension().toString()
|
||||
}
|
||||
|
||||
fun fooInClass(s: String) = s.fooInClass().bar
|
||||
|
||||
fun fooInClassNoReceiver(s: String) = s.fooInClassNoReceiver().bar
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = "Hello, world!".foo().bar
|
||||
if (result != "13") return "fail 1: $result"
|
||||
|
||||
result = C().fooInClass("Hello, world!")
|
||||
|
||||
if (result != "13") return "fail 2: $result"
|
||||
|
||||
result = C().fooInClassNoReceiver("Hello, world!")
|
||||
|
||||
if (result != "3") return "fail 3: $result"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
interface B<T> {
|
||||
val bar: T
|
||||
}
|
||||
|
||||
class S(val value: String) {
|
||||
|
||||
fun bar() = value
|
||||
|
||||
fun foo(): B<String> {
|
||||
val p = S("OK");
|
||||
return object : B<String> {
|
||||
//we shouldn't capture this@S in such case
|
||||
override val bar: String = p.bar()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return S("fail").foo().bar
|
||||
}
|
||||
|
||||
// 0 this$0
|
||||
Reference in New Issue
Block a user