mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-56628 Missing incompatible assignment when conditionally returning from a method
This commit is contained in:
+4
-5
@@ -18,6 +18,7 @@ package org.jetbrains.plugins.groovy.codeInspection.assignment;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -31,6 +32,7 @@ import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentLabel;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.branch.GrReturnStatement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression;
|
||||
@@ -109,11 +111,8 @@ public class GroovyAssignabilityCheckInspection extends BaseInspection {
|
||||
public void visitReturnStatement(GrReturnStatement returnStatement) {
|
||||
super.visitReturnStatement(returnStatement);
|
||||
|
||||
final PsiElement parent = returnStatement.getParent();
|
||||
if (!(parent instanceof GrOpenBlock)) return;
|
||||
final PsiElement element = parent.getParent();
|
||||
if (!(element instanceof GrMethod)) return;
|
||||
GrMethod method = (GrMethod)element;
|
||||
final GrMethod method = PsiTreeUtil.getParentOfType(returnStatement, GrMethod.class, true, GrClosableBlock.class);
|
||||
if (method == null) return;
|
||||
|
||||
final GrExpression value = returnStatement.getReturnValue();
|
||||
final PsiType expectedType = method.getReturnType();
|
||||
|
||||
@@ -274,13 +274,10 @@ public class GroovyHighlightingTest extends LightCodeInsightFixtureTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testCollectionAssignments() throws Exception {
|
||||
doTest(new GroovyAssignabilityCheckInspection());
|
||||
}
|
||||
public void testCollectionAssignments() {doTest(new GroovyAssignabilityCheckInspection()); }
|
||||
public void testReturnAssignability() {doTest(new GroovyAssignabilityCheckInspection()); }
|
||||
|
||||
public void testNumberDuplicatesInMaps() throws Exception {doTest();}
|
||||
|
||||
public void testMapNotAcceptedAsStringParameter() {
|
||||
doTest();
|
||||
}
|
||||
public void testMapNotAcceptedAsStringParameter() {doTest();}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
File foo() {
|
||||
List<Integer> ints = []
|
||||
if (ints.empty) {
|
||||
print {return 42}
|
||||
for (x in ints) {
|
||||
<warning descr="Cannot assign 'Integer' to 'File'">return 43</warning>
|
||||
}
|
||||
}
|
||||
<warning descr="Cannot assign 'Integer' to 'File'">67</warning>
|
||||
}
|
||||
Reference in New Issue
Block a user