diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt index 9081b166d94..3acb7dea259 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt @@ -123,18 +123,17 @@ class KotlinResolutionCallbacksImpl( } } - if (!hasReturnWithoutExpression) { - val lastExpressionArgument = getLastDeparentesizedExpression(psiCallArgument)?.let { lastExpression -> - if (expectedReturnType?.isUnit() == true) return@let null // coercion to Unit + val lastExpressionArgument = getLastDeparentesizedExpression(psiCallArgument)?.let { lastExpression -> + if (expectedReturnType?.isUnit() == true) return@let null // coercion to Unit - // todo lastExpression can be if without else - val lastExpressionType = trace.getType(lastExpression) - val lastExpressionTypeInfo = KotlinTypeInfo(lastExpressionType, lambdaInfo.dataFlowInfoAfter ?: functionTypeInfo.dataFlowInfo) - createCallArgument(lastExpression, lastExpressionTypeInfo) - } - returnArguments.addIfNotNull(lastExpressionArgument) + // todo lastExpression can be if without else + val lastExpressionType = if (hasReturnWithoutExpression) null else trace.getType(lastExpression) + val lastExpressionTypeInfo = KotlinTypeInfo(lastExpressionType, lambdaInfo.dataFlowInfoAfter ?: functionTypeInfo.dataFlowInfo) + createCallArgument(lastExpression, lastExpressionTypeInfo) } + returnArguments.addIfNotNull(lastExpressionArgument) + return returnArguments } diff --git a/compiler/testData/codegen/box/nonLocalReturns/returnInsideTwoLambdas.kt b/compiler/testData/codegen/box/nonLocalReturns/returnInsideTwoLambdas.kt new file mode 100644 index 00000000000..4f0dc889db3 --- /dev/null +++ b/compiler/testData/codegen/box/nonLocalReturns/returnInsideTwoLambdas.kt @@ -0,0 +1,28 @@ +fun outer(command: () -> T) : T = command() + +inline fun inner(action: () -> K): K = action() + +fun test1(): String { + outer { + inner { + return@outer + } + } + + return "O" +} + +fun test2(): String { + outer { + return@outer + inner { + } + } + + return "K" +} + + +fun box(): String { + return test1() + test2() +} \ No newline at end of file diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 34ac5f6dd5c..70b9bbe74ba 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -12422,6 +12422,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes doTest(fileName); } + @TestMetadata("returnInsideTwoLambdas.kt") + public void testReturnInsideTwoLambdas() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/nonLocalReturns/returnInsideTwoLambdas.kt"); + doTest(fileName); + } + @TestMetadata("use.kt") public void testUse() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/nonLocalReturns/use.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 3734990aab8..f76355fec6e 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -12422,6 +12422,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("returnInsideTwoLambdas.kt") + public void testReturnInsideTwoLambdas() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/nonLocalReturns/returnInsideTwoLambdas.kt"); + doTest(fileName); + } + @TestMetadata("use.kt") public void testUse() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/nonLocalReturns/use.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 15f2297f6de..f3b613fa9f2 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -12422,6 +12422,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes doTest(fileName); } + @TestMetadata("returnInsideTwoLambdas.kt") + public void testReturnInsideTwoLambdas() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/nonLocalReturns/returnInsideTwoLambdas.kt"); + doTest(fileName); + } + @TestMetadata("use.kt") public void testUse() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/nonLocalReturns/use.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index c0d2725b018..ce268d91db3 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -13484,6 +13484,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { doTest(fileName); } + @TestMetadata("returnInsideTwoLambdas.kt") + public void testReturnInsideTwoLambdas() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/nonLocalReturns/returnInsideTwoLambdas.kt"); + doTest(fileName); + } + @TestMetadata("use.kt") public void testUse() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/nonLocalReturns/use.kt");