Ignore annotations from expression constraints.

We don't account them correctly anyway: if two constraints produce the same type with different annotations the second one will be completely ignored. And it's completely unclear how to combine them properly. This depends on annotation semantics.

GitOrigin-RevId: 5d9c9818254e1fc991f144f136c292833753442b
This commit is contained in:
Tagir Valeev
2020-01-14 09:08:13 +00:00
committed by intellij-monorepo-bot
parent 5339a08706
commit 7b91cc9300
3 changed files with 32 additions and 0 deletions
@@ -30,6 +30,9 @@ public class ExpressionCompatibilityConstraint extends InputOutputConstraintForm
if (!PsiPolyExpressionUtil.isPolyExpression(myExpression)) {
PsiType exprType = myExpression.getType();
if (exprType != null) {
exprType = exprType.annotate(TypeAnnotationProvider.EMPTY);
}
if (session.isProperType(myT)) {
final boolean assignmentCompatible = exprType == null || TypeConversionUtil.isAssignable(myT, exprType);
@@ -0,0 +1,25 @@
import ambiguous.*;
class Test {
void run1() {
String result = compute(() -> {
return Math.random() > 0.5 ? getResult() : getResult2();
});
if (result == null) {}
}
void run() {
String result = compute(() -> {
return Math.random() > 0.5 ? getResult() : null;
});
if (result == null) {}
}
native @NotNull String getResult();
native @Nullable String getResult2();
public native static <T> T compute(Computable<T> action);
}
interface Computable<T> {
T compute();
}
@@ -155,6 +155,10 @@ public class DataFlowInspection8Test extends DataFlowInspectionTestCase {
public void testCapturedWildcardNotNull() { doTest(); }
public void testVarargNotNull() { doTestWithCustomAnnotations(); }
public void testIgnoreNullabilityOnPrimitiveCast() { doTestWithCustomAnnotations();}
public void testTypeUseLambdaReturn() {
setupTypeUseAnnotations("ambiguous", myFixture);
doTest();
}
public void testArrayComponentAndMethodAnnotationConflict() {
setupAmbiguousAnnotations("withTypeUse", myFixture);