Fix capturing outer this in some cases in JVM codegen
When property initializer of some inner entity (e.g. anonymous object) contains a reference to some outer entity (say, a property of the outer class), we need to make sure we called "lookupInContext" on this entity's owner class, so that "setCaptureThis" was called on the appropriate closure #KT-4176 Fixed
This commit is contained in:
+15
@@ -0,0 +1,15 @@
|
||||
trait T {
|
||||
fun result(): String
|
||||
}
|
||||
|
||||
class A(val x: String) {
|
||||
fun getx() = x
|
||||
|
||||
fun foo() = object : T {
|
||||
val bar = getx()
|
||||
|
||||
override fun result() = bar
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = A("OK").foo().result()
|
||||
@@ -0,0 +1,13 @@
|
||||
trait T {
|
||||
fun result(): String
|
||||
}
|
||||
|
||||
class A(val x: String) {
|
||||
fun foo() = object : T {
|
||||
fun bar() = x
|
||||
|
||||
override fun result() = bar()
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = A("OK").foo().result()
|
||||
@@ -0,0 +1,13 @@
|
||||
trait T {
|
||||
fun result(): String
|
||||
}
|
||||
|
||||
class A(val x: String) {
|
||||
fun foo() = object : T {
|
||||
val bar = x
|
||||
|
||||
override fun result() = bar
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = A("OK").foo().result()
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
trait T {
|
||||
fun result(): String
|
||||
}
|
||||
|
||||
class A(val x: String) {
|
||||
fun foo() = object : T {
|
||||
fun bar() = object : T {
|
||||
fun baz() = object : T {
|
||||
val y = x
|
||||
override fun result() = y
|
||||
}
|
||||
override fun result() = baz().result()
|
||||
}
|
||||
override fun result() = bar().result()
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = A("OK").foo().result()
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
trait T {
|
||||
fun result(): String
|
||||
}
|
||||
|
||||
open class B(val x: String)
|
||||
|
||||
class A : B("OK") {
|
||||
fun foo() = object : T {
|
||||
val bar = x
|
||||
|
||||
override fun result() = bar
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = A().foo().result()
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
trait T {
|
||||
fun result(): String
|
||||
}
|
||||
|
||||
abstract class A<Z>(val x: Z)
|
||||
|
||||
open class B : A<String>("OK")
|
||||
|
||||
class C : B() {
|
||||
fun foo() = object : T {
|
||||
val bar = x
|
||||
|
||||
override fun result() = bar
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = C().foo().result()
|
||||
@@ -0,0 +1,17 @@
|
||||
open class Z(val s: Int) {
|
||||
open fun a() {}
|
||||
}
|
||||
|
||||
class B(val x: Int) {
|
||||
fun foo() {
|
||||
class X : Z(x) {
|
||||
|
||||
}
|
||||
X()
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
B(1).foo()
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user