java error tooltips: highlight type arguments according to TypeConversionUtil#isAssigned (IDEA-94965)

GitOrigin-RevId: db456a719c885e055a5a1bd379a63120aeba1aee
This commit is contained in:
Anna Kozlova
2019-07-15 10:19:50 +02:00
committed by intellij-monorepo-bot
parent 97e799fdaa
commit 9f6014adfc
3 changed files with 27 additions and 1 deletions

View File

@@ -2832,7 +2832,10 @@ public class HighlightUtil extends HighlightUtilBase {
PsiTypeParameter rTypeParameter = i >= rTypeParams.length ? null : rTypeParams[i];
PsiType lSubstitutedType = lTypeParameter == null ? null : lTypeData.third.substitute(lTypeParameter);
PsiType rSubstitutedType = rTypeParameter == null ? null : rTypeData.third.substitute(rTypeParameter);
boolean matches = Comparing.equal(lSubstitutedType, rSubstitutedType);
boolean matches = lSubstitutedType == rSubstitutedType ||
lSubstitutedType != null &&
rSubstitutedType != null &&
TypeConversionUtil.typesAgree(lSubstitutedType, rSubstitutedType, true);
String openBrace = i == 0 ? "<" : "";
String closeBrace = i == typeParamColumns - 1 ? ">" : ",";
requiredRow.append("<td>").append(lTypeParams.length == 0 ? "" : openBrace).append(redIfNotMatch(lSubstitutedType, matches))

View File

@@ -0,0 +1,7 @@
class MyTest {
void subject(Generic<? extends Number, Number, Integer> pSuper,
Generic<Integer, Integer, Integer> pSub) {
<error descr="Incompatible types. Found: 'Generic<java.lang.Integer,java.lang.Integer,java.lang.Integer>', required: 'Generic<? extends java.lang.Number,java.lang.Number,java.lang.Integer>'">pSuper = pSub</error>;
}
}
class Generic<U, V, W> {}

View File

@@ -16,6 +16,7 @@
package com.intellij.java.codeInsight.daemon.lambda;
import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
import com.intellij.codeInsight.daemon.impl.HighlightInfoType;
import com.intellij.codeInspection.LocalInspectionTool;
import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection;
import com.intellij.codeInspection.uncheckedWarnings.UncheckedWarningLocalInspection;
@@ -26,6 +27,7 @@ import com.intellij.pom.java.LanguageLevel;
import com.intellij.testFramework.IdeaTestUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.junit.Assert;
//javac option to dump bounds: -XDdumpInferenceGraphsTo=
public class GenericsHighlighting8Test extends LightDaemonAnalyzerTestCase {
@@ -1039,6 +1041,20 @@ public class GenericsHighlighting8Test extends LightDaemonAnalyzerTestCase {
doTest();
}
public void testTooltipTypesAgree() {
doTest();
doHighlighting()
.stream()
.filter(info -> info.type == HighlightInfoType.ERROR)
.forEach(info -> Assert.assertEquals("<html><body>Incompatible types." +
"<table><tr><td>Required:</td>" +
"<td>Generic</td><td>&lt;? extends Number,</td><td><font color='red'><b>java.lang.Number</b></font>,</td><td>Integer&gt;</td></tr>" +
"<tr><td>Found:</td>" +
"<td>Generic</td><td>&lt;Integer,</td><td><font color='red'><b>java.lang.Integer</b></font>,</td><td>Integer&gt;</td></tr>" +
"</table></body></html>",
info.getToolTip()));
}
public void testBridgeMethodOverriding() { doTest(); }
public void testNestedWildcardsWithImplicitBounds() { doTest(); }
public void testCallOnRawWithExplicitTypeArguments() { doTest(); }