KT-13583: allow local classes to capture members of outer classes
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
package foo
|
||||
|
||||
open class A(private val x: String) {
|
||||
fun foo(): String {
|
||||
class B : A("fail1: simple nested") {
|
||||
fun bar() = x
|
||||
}
|
||||
return B().bar()
|
||||
}
|
||||
}
|
||||
|
||||
open class A1(private val x: String) {
|
||||
fun foo(): String {
|
||||
class B1 {
|
||||
fun bar(): String {
|
||||
class C1 : A1("fail2: deeply nested") {
|
||||
fun baz() = x
|
||||
}
|
||||
return C1().baz()
|
||||
}
|
||||
}
|
||||
return B1().bar()
|
||||
}
|
||||
}
|
||||
|
||||
open class A2(private val x: String) {
|
||||
fun foo(): String {
|
||||
class B2 : A2("fail3: deeply nested") {
|
||||
fun bar(): String {
|
||||
class C2 {
|
||||
fun baz() = x
|
||||
}
|
||||
return C2().baz()
|
||||
}
|
||||
}
|
||||
return B2().bar()
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val result = A("OK").foo()
|
||||
if (result != "OK") return result
|
||||
|
||||
val result1 = A1("OK").foo()
|
||||
if (result1 != "OK") return result1
|
||||
|
||||
val result2 = A2("OK").foo()
|
||||
if (result2 != "OK") return result2
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// copied from JVM backend tests
|
||||
package foo
|
||||
|
||||
open class X(private val n: String) {
|
||||
|
||||
fun foo(): String {
|
||||
return object : X("inner") {
|
||||
fun print(): String {
|
||||
return n;
|
||||
}
|
||||
}.print()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
return X("OK").foo()
|
||||
}
|
||||
Reference in New Issue
Block a user