Allow to process return statements without parent KtDeclaration (EA-70883)
This commit is contained in:
committed by
Nikolay Krasko
parent
1e50847985
commit
938a435346
+2
-1
@@ -571,8 +571,9 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
||||
parentDeclaration = PsiTreeUtil.getParentOfType(parentDeclaration, KtDeclaration.class);
|
||||
}
|
||||
|
||||
assert parentDeclaration != null : "Can't find parent declaration for " + expression.getText();
|
||||
// Parent declaration can be null in code fragments or in some bad error expressions
|
||||
DeclarationDescriptor declarationDescriptor = context.trace.get(DECLARATION_TO_DESCRIPTOR, parentDeclaration);
|
||||
|
||||
Pair<FunctionDescriptor, PsiElement> containingFunInfo =
|
||||
BindingContextUtils.getContainingFunctionSkipFunctionLiterals(declarationDescriptor, false);
|
||||
FunctionDescriptor containingFunctionDescriptor = containingFunInfo.getFirst();
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
fun foo(): Int? {
|
||||
val a: Int? = 1
|
||||
<caret>return a
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<error descr="[RETURN_NOT_ALLOWED] 'return' is not allowed here">return a</error>
|
||||
@@ -0,0 +1 @@
|
||||
<error descr="[UNRESOLVED_REFERENCE] Unresolved reference: suppress">@file:suppress</error>(<error descr="[RETURN_NOT_ALLOWED] 'return' is not allowed here"><error descr="[RETURN_NOT_ALLOWED] 'return' is not allowed here">return <error descr="[UNRESOLVED_REFERENCE] Unresolved reference: a"><error descr="[UNRESOLVED_REFERENCE] Unresolved reference: a">a</error></error></error></error>)
|
||||
@@ -630,6 +630,12 @@ public class PsiCheckerTestGenerated extends AbstractPsiCheckerTest {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/checker/recovery/namelessToplevelDeclarations.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("returnInFileAnnotation.kt")
|
||||
public void testReturnInFileAnnotation() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/checker/recovery/returnInFileAnnotation.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/checker/rendering")
|
||||
|
||||
+6
@@ -151,6 +151,12 @@ public class CodeFragmentHighlightingTestGenerated extends AbstractCodeFragmentH
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("startingFromReturn.kt")
|
||||
public void testStartingFromReturn() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/checker/codeFragments/startingFromReturn.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("withoutBodyFunction.kt")
|
||||
public void testWithoutBodyFunction() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/checker/codeFragments/withoutBodyFunction.kt");
|
||||
|
||||
Reference in New Issue
Block a user