inference: don't erase types when target type is parameterized with unbounded wildcards only, in this case no unchecked warning would be generated and the types won't be affected by unchecked warning clause

This commit is contained in:
Anna.Kozlova
2016-11-23 11:53:29 +01:00
parent 87d9169d09
commit 049a253fdf
2 changed files with 39 additions and 1 deletions
@@ -15,6 +15,7 @@
*/
package com.intellij.psi.impl.source.resolve.graphInference.constraints;
import com.intellij.codeInsight.daemon.impl.analysis.JavaGenericsUtil;
import com.intellij.psi.*;
import com.intellij.psi.impl.source.resolve.graphInference.InferenceSession;
import com.intellij.psi.impl.source.resolve.graphInference.InferenceVariable;
@@ -51,7 +52,7 @@ public class ExpressionCompatibilityConstraint extends InputOutputConstraintForm
final PsiType type = myExpression.getType();
session.registerIncompatibleErrorMessage((type != null ? type.getPresentableText() : myExpression.getText()) + " is not compatible with " + session.getPresentableText(myT));
}
else if (TypeCompatibilityConstraint.isUncheckedConversion(myT, exprType)) {
else if (TypeCompatibilityConstraint.isUncheckedConversion(myT, exprType) && !JavaGenericsUtil.isReifiableType(myT)) {
session.setErasedDuringApplicabilityCheck();
}
return assignmentCompatible;
@@ -1,3 +1,4 @@
import java.util.function.Consumer;
class Test {
private static AG<AE> foo(Class clz) {
return (AG<AE>) foo1(clz);
@@ -15,3 +16,39 @@ class Test {
}
class Test1 {
static class D<T> {
public D(Consumer<T> c, Class<?> cl) {
}
static <M> D<M> create(Consumer<M> c, Class<?> ck) {
return new D<>(c, ck);
}
}
{
Class c = D.class;
D<String> d = new D<>(s -> s.isEmpty(), c);
D<String> d1 = D.create(s -> s.isEmpty(), c);
}
}
class Test2 {
static class D<T> {
public D(Consumer<T> c, Class<? extends String> cl) {
}
static <M> D<M> create(Consumer<M> c, Class<? extends String> ck) {
return new D<>(c, ck);
}
}
{
Class c = D.class;
D<String> d = new D<>(s -> s.<error descr="Cannot resolve method 'isEmpty()'">isEmpty</error>(), c);
D<String> d1 = D.create(s -> s.<error descr="Cannot resolve method 'isEmpty()'">isEmpty</error>(), c);
}
}