java inference: setup initial constraints with respect of unchecked warning rules (IDEA-259701)

GitOrigin-RevId: e922b0cdfdecf6dfc3a50a334aa21e084aa1dd97
This commit is contained in:
Anna Kozlova
2021-01-18 14:33:02 +01:00
committed by intellij-monorepo-bot
parent d8b0b80a26
commit ad18c7f009
3 changed files with 18 additions and 0 deletions

View File

@@ -159,6 +159,9 @@ public class InferenceSession {
if (args[i] != null && isPertinentToApplicability(args[i], method)) {
PsiType parameterType = getParameterType(parameters, i, mySiteSubstitutor, varargs);
if (method != null && PsiUtil.isRawSubstitutor(method, mySiteSubstitutor)) {
parameterType = TypeConversionUtil.erasure(parameterType);
}
LOG.assertTrue(parameterType != null);
if (!ignoreLambdaConstraintTree(args[i])) {
addConstraint(new ExpressionCompatibilityConstraint(args[i], substituteWithInferenceVariables(parameterType)));

View File

@@ -0,0 +1,13 @@
import java.util.function.Consumer;
class MyTest {
void m(Provider provider) {
provider.provide(new <error descr="Class 'Anonymous class derived from Consumer' must either be declared abstract or implement abstract method 'accept(T)' in 'Consumer'">Consumer<></error>() {
<error descr="Method does not override method from its superclass">@Override</error>
public void accept(String s) { }
});
}
static class Provider<T> {
void provide(Consumer<String> consumer){}
}
}

View File

@@ -113,6 +113,8 @@ public class Diamond8HighlightingTest extends LightDaemonAnalyzerTestCase {
public void testNestedDiamondsAnonymousCase() { doTest();}
public void testDiamondsUncheckedWarning() { doTest();}
private void doTest() {
doTest(BASE_PATH + "/" + getTestName(false) + ".java", false, false);
}