Remove error diagnostic from return in multideclaration
#KT-5100 Fixed
This commit is contained in:
+6
-1
@@ -531,7 +531,12 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (expression.getTargetLabel() == null) {
|
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);
|
DeclarationDescriptor declarationDescriptor = context.trace.get(DECLARATION_TO_DESCRIPTOR, parentDeclaration);
|
||||||
Pair<FunctionDescriptor, PsiElement> containingFunInfo =
|
Pair<FunctionDescriptor, PsiElement> containingFunInfo =
|
||||||
BindingContextUtils.getContainingFunctionSkipFunctionLiterals(declarationDescriptor, false);
|
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)
|
||||||
|
}
|
||||||
+6
@@ -4633,6 +4633,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("SimpleVals.kt")
|
||||||
public void testSimpleVals() throws Exception {
|
public void testSimpleVals() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/multiDecl/SimpleVals.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/multiDecl/SimpleVals.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user