JVM IR: Turn static callable references into singletons

This commit is contained in:
Steven Schäfer
2020-03-05 11:35:51 +01:00
committed by Dmitry Petrov
parent ac5c255c20
commit bb5a639153
9 changed files with 196 additions and 10 deletions
+20
View File
@@ -0,0 +1,20 @@
// TARGET_BACKEND: JVM
var capturedLambda: ((Int) -> Int)? = null
fun captureLambda(): Boolean {
val lambda = { x: Int -> x + 1 }
if (capturedLambda == null) {
capturedLambda = lambda
} else if (capturedLambda !== lambda) {
return false
}
return true
}
fun box(): String {
captureLambda()
if (!captureLambda())
return "FAIL"
return "OK"
}