diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingVisitor.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingVisitor.java index 0f65fc59c42..9c04006e664 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingVisitor.java @@ -531,7 +531,12 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor { } if (expression.getTargetLabel() == null) { - assert parentDeclaration != null; + while (parentDeclaration instanceof JetMultiDeclaration) { + //TODO: It's hacking fix for KT-5100: Strange "Return is not allowed here" for multi-declaration initializer with elvis expression + parentDeclaration = PsiTreeUtil.getParentOfType(parentDeclaration, JetDeclaration.class); + } + + assert parentDeclaration != null : "Can't find parent declaration for " + expression.getText(); DeclarationDescriptor declarationDescriptor = context.trace.get(DECLARATION_TO_DESCRIPTOR, parentDeclaration); Pair containingFunInfo = BindingContextUtils.getContainingFunctionSkipFunctionLiterals(declarationDescriptor, false); diff --git a/compiler/testData/codegen/box/multiDecl/returnInElvis.kt b/compiler/testData/codegen/box/multiDecl/returnInElvis.kt new file mode 100644 index 00000000000..9f381d75225 --- /dev/null +++ b/compiler/testData/codegen/box/multiDecl/returnInElvis.kt @@ -0,0 +1,22 @@ +data class Z(val p: String, val k: String) + + +fun create(p: Boolean): Z? { + return if (p) { + Z("O", "K") + } + else { + null; + } +} + +fun test(p: Boolean): String { + val (a, b) = create(p) ?: return "null" + return a + b +} + +fun box(): String { + if (test(false) != "null") return "fail 1: ${test(false)}" + + return test(true) +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java index 9f627f9ab0c..189244ff67f 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java @@ -4633,6 +4633,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("returnInElvis.kt") + public void testReturnInElvis() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/multiDecl/returnInElvis.kt"); + doTest(fileName); + } + @TestMetadata("SimpleVals.kt") public void testSimpleVals() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/multiDecl/SimpleVals.kt");