Remove error diagnostic from return in multideclaration

#KT-5100 Fixed
This commit is contained in:
Michael Bogdanov
2015-06-03 17:21:33 +03:00
parent a321e8eef5
commit 83f04501be
3 changed files with 34 additions and 1 deletions
@@ -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<FunctionDescriptor, PsiElement> containingFunInfo =
BindingContextUtils.getContainingFunctionSkipFunctionLiterals(declarationDescriptor, false);
@@ -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)
}
@@ -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");