Properly capture extension receiver for array convention expressions in object constructor

#KT-19389 Fixed
This commit is contained in:
Mikhael Bogdanov
2019-02-05 11:37:23 +01:00
parent 3943bd1b15
commit 9ab6062295
12 changed files with 155 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
public fun <T, R> myWith(receiver: T, block: T.() -> R): R {
return receiver.block()
}
object Foo2 {
operator fun Any?.get(key: String) = "OK"
}
object Main {
fun bar() = myWith(Foo2) {
val x = object {
val y = 38["Hello!"]
}
x.y
}
}
fun box(): String {
return Main.bar()
}
+27
View File
@@ -0,0 +1,27 @@
var result = "fail"
public fun <T, R> myWith(receiver: T, block: T.() -> R): R {
return receiver.block()
}
object Foo2 {
operator fun Any?.get(key: String) = "OK"
operator fun Any?.set(key: String, value: String) {
result = value
}
}
object Main {
fun bar() = myWith(Foo2) {
val x = object {
init {
38["Hello!"] = "OK"
}
}
result
}
}
fun box(): String {
return Main.bar()
}
@@ -0,0 +1,24 @@
// FILE: 1.kt
public inline fun <T, R> myWith(receiver: T, block: T.() -> R): R {
return receiver.block()
}
// FILE: 2.kt
//NO_CHECK_LAMBDA_INLINING
object Foo2 {
operator fun Any?.get(key: String) = "OK"
}
object Main {
fun bar() = myWith(Foo2) {
val x = object {
val y = 38["Hello!"]
}
x.y
}
}
fun box(): String {
return Main.bar()
}