don't highlight part of poly conditional expression when it's type is not defined, would be highlighted on top level (IDEA-171431)

This commit is contained in:
Anna.Kozlova
2017-04-29 19:28:48 +02:00
parent 3895d5a1dd
commit 568bb75fbc
3 changed files with 18 additions and 0 deletions
@@ -50,6 +50,7 @@ import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.*;
import com.intellij.psi.impl.source.resolve.JavaResolveUtil;
import com.intellij.psi.impl.source.resolve.graphInference.InferenceSession;
import com.intellij.psi.impl.source.resolve.graphInference.PsiPolyExpressionUtil;
import com.intellij.psi.impl.source.tree.java.PsiLiteralExpressionImpl;
import com.intellij.psi.impl.source.tree.java.PsiReferenceExpressionImpl;
import com.intellij.psi.javadoc.PsiDocComment;
@@ -2540,6 +2541,9 @@ public class HighlightUtil extends HighlightUtilBase {
PsiType thenType = thenExpression.getType();
if (thenType == null || type == null) return null;
if (conditionalExpression.getType() == null) {
if (PsiUtil.isLanguageLevel8OrHigher(conditionalExpression) && PsiPolyExpressionUtil.isPolyExpression(conditionalExpression)) {
return null;
}
// cannot derive type of conditional expression
// elseType will never be cast-able to thenType, so no quick fix here
return createIncompatibleTypeHighlightInfo(thenType, type, expression.getTextRange(), 0);
@@ -0,0 +1,10 @@
class Test{
void test() {
B b = new B<error descr="'B(java.lang.String, java.lang.String)' in 'Test.B' cannot be applied to '(?)'">(true == false ? "bar" : null)</error>;
}
class B {
B(String c, String d ) {}
}
}
@@ -1024,4 +1024,8 @@ public class GenericsHighlighting8Test extends LightDaemonAnalyzerTestCase {
public void testSameErasureForStaticMethodsInInterfaces() throws Exception {
doTest();
}
public void testConditionalExpressionInIncompleteCall() throws Exception {
doTest();
}
}