ensure no inference from not inferred var (IDEA-193828)

This commit is contained in:
Anna Kozlova
2018-06-13 20:56:56 +03:00
parent 3dcd60cbb5
commit dc43909e2c
3 changed files with 20 additions and 2 deletions

View File

@@ -259,7 +259,8 @@ public class PsiTypesUtil {
}
else if (parent instanceof PsiAssignmentExpression) {
if (PsiUtil.checkSameExpression(element, ((PsiAssignmentExpression)parent).getRExpression())) {
return ((PsiAssignmentExpression)parent).getLExpression().getType();
PsiType type = ((PsiAssignmentExpression)parent).getLExpression().getType();
return !PsiType.NULL.equals(type) ? type : null;
}
}
else if (parent instanceof PsiReturnStatement) {

View File

@@ -0,0 +1,17 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
class MyTest {
public List<Integer> someMethod() {
<error descr="Cannot infer type: 'var' on variable without initializer">var</error> listOfInteger;
Integer[] arrayOfInteger = {2, 4, 8};
<error descr="Incompatible types. Found: 'java.util.ArrayList<java.lang.Integer>', required: 'null'">listOfInteger = Arrays.stream(arrayOfInteger)
.filter(number -> number >= 4)
.collect(Collectors.toCollection(ArrayList::new))</error>;
return listOfInteger;
}
}

View File

@@ -196,7 +196,7 @@ public class GraphInferenceHighlightingTest extends LightDaemonAnalyzerTestCase
public void testApplicabilityCheckFailsExpressionTypeCheckPasses() {
doTest();
}
public void testNotInferredVarShouldNotBeUsedForInferenceJava10() { doTest(); }
public void testTopLevelParentNoParameters() {
doTest();
}