inference: when unchecked conversion was applied, resolve variables against raw substitutor

This commit is contained in:
Anna Kozlova
2016-08-17 13:46:09 +03:00
parent 20f36c672b
commit 1bece25b95
6 changed files with 35 additions and 11 deletions

View File

@@ -1187,6 +1187,12 @@ public class InferenceSession {
@NotNull
private PsiSubstitutor resolveSubset(Collection<InferenceVariable> vars, PsiSubstitutor substitutor) {
if (myErased) {
for (InferenceVariable var : vars) {
substitutor = substitutor.put(var, null);
}
}
for (InferenceVariable var : vars) {
final PsiType instantiation = var.getInstantiation();
final PsiType type = instantiation == PsiType.NULL ? checkBoundsConsistency(substitutor, var) : instantiation;
@@ -1228,12 +1234,7 @@ public class InferenceSession {
type = PsiType.getJavaLangRuntimeException(myManager, GlobalSearchScope.allScope(myManager.getProject()));
}
else {
if (myErased) {
type = null;
}
else {
type = var.getBounds(InferenceBound.UPPER).size() == 1 ? myPolicy.getInferredTypeWithNoConstraint(myManager, upperBound).first : upperBound;
}
type = var.getBounds(InferenceBound.UPPER).size() == 1 ? myPolicy.getInferredTypeWithNoConstraint(myManager, upperBound).first : upperBound;
}
if (type instanceof PsiIntersectionType) {

View File

@@ -7,8 +7,8 @@ public class Sample {
<B> B bar(G<B> gb) {return null;}
void f(G1 g1) {
<error descr="Incompatible types. Found: 'java.lang.Object', required: 'Sample.G<java.lang.String>'">G<String> l11 = bar(g1);</error>
<error descr="Incompatible types. Found: 'java.lang.Object', required: 'java.lang.String'">String l1 = bar(g1);</error>
G<String> l11 = bar<error descr="'bar(Sample.G<B>)' in 'Sample' cannot be applied to '(Sample.G1)'">(g1)</error>;
String l1 = bar<error descr="'bar(Sample.G<B>)' in 'Sample' cannot be applied to '(Sample.G1)'">(g1)</error>;
Object o = bar(g1);
}
}

View File

@@ -6,7 +6,7 @@ class Test {
}
void m(List l){
<error descr="Incompatible types. Found: 'java.lang.Object', required: 'boolean'">boolean foo = foo(l);</error>
<error descr="Incompatible types. Found: 'java.lang.Object', required: 'java.lang.String'">String s = foo(l);</error>
boolean foo = foo<error descr="'foo(java.util.List<T>)' in 'Test' cannot be applied to '(java.util.List)'">(l)</error>;
String s = foo<error descr="'foo(java.util.List<T>)' in 'Test' cannot be applied to '(java.util.List)'">(l)</error>;
}
}

View File

@@ -0,0 +1,19 @@
import java.util.function.Consumer;
interface A<T> {
void locateDefinition();
}
class Test {
public static <T extends A> void bar(final T member, final Consumer<T> processor) {}
public static <T extends A<?>> void bar1(final T member, final Consumer<T> processor) {}
public static <T extends A<T>> void bar2(final T member, final Consumer<T> processor) {}
public static void foo(final A member) {
bar(member, symbol -> symbol.locateDefinition());
bar1(member, symbol -> symbol.locateDefinition());
bar2(member, symbol -> symbol.locateDefinition());
}
}

View File

@@ -4,7 +4,7 @@ import java.util.Set;
abstract class Test {
public void foo(List list) {
set<error descr="Ambiguous method call: both 'Test.set(Set<List>, List)' and 'Test.set(Set, List)' match">(get(), list)</error>;
set<error descr="Ambiguous method call: both 'Test.set(Set<List>, List)' and 'Test.set(Set<Object>, List<?>)' match">(get(), list)</error>;
}
abstract <Y> Set<Y> get();

View File

@@ -331,6 +331,10 @@ public class NewLambdaHighlightingTest extends LightDaemonAnalyzerTestCase {
doTest();
}
public void testUncheckedConstraintOnInferenceVariableWithProperUpperBound() throws Exception {
doTest();
}
private void doTest() {
doTest(false);
}