[PL] Fix: Respect inlined array constructor lambdas

This commit is contained in:
Dmitriy Dolovov
2023-03-23 17:11:34 +01:00
committed by Space Team
parent 5baeae3bfd
commit 66532d714e
4 changed files with 33 additions and 3 deletions
@@ -161,3 +161,21 @@ fun newNonInlineFunctionInOpenClassImpl(oci: OpenClassImpl, x: Int): String = oc
fun inlineLambdaToNoinlineLambda(x: Int): String = Functions.inlineLambdaToNoinlineLambda(x) { if (it > 0) it.toString() else return "inlineLambdaToNoinlineLambda($x)" }
fun inlineLambdaToCrossinlineLambda(x: Int): String = Functions.inlineLambdaToCrossinlineLambda(x) { if (it > 0) it.toString() else return "inlineLambdaToCrossinlineLambda($x)" }
fun nonLocalReturnFromArrayConstructorLambda(expected: String, unexpected: String): String = Array(1) outer@{
Array(1) {
if ('1' in "123") { // The condition that is always true.
return@outer expected
}
unexpected
}[0]
}[0]
fun nonLocalReturnFromIntArrayConstructorLambda(expected: Int, unexpected: Int): Int = IntArray(1) outer@{
IntArray(1) {
if ('1' in "123") { // The condition that is always true.
return@outer expected
}
unexpected
}[0]
}[0]
@@ -119,4 +119,7 @@ fun box() = abiTest {
expectFailure(linkage("Illegal non-local return: The return target is function 'inlineLambdaToNoinlineLambda' while only the following return targets are allowed: lambda in function 'inlineLambdaToNoinlineLambda'")) { inlineLambdaToNoinlineLambda(-3) }
expectSuccess("Functions.inlineLambdaToCrossinlineLambda(5) { 10 }") { inlineLambdaToCrossinlineLambda(5) }
expectFailure(linkage("Illegal non-local return: The return target is function 'inlineLambdaToCrossinlineLambda' while only the following return targets are allowed: lambda in function 'inlineLambdaToCrossinlineLambda'")) { inlineLambdaToCrossinlineLambda(-5) }
expectSuccess("success") { nonLocalReturnFromArrayConstructorLambda("success", "failure") }
expectSuccess(100) { nonLocalReturnFromIntArrayConstructorLambda(100, -100) }
}