raw substitutor when erasure happened during inference

This commit is contained in:
Anna Kozlova
2014-03-27 20:54:26 +01:00
parent 87ef3f9d97
commit e55a20cc24
3 changed files with 17 additions and 3 deletions
@@ -366,7 +366,10 @@ public class InferenceSession {
final InferenceVariable inferenceVariable = shouldResolveAndInstantiate(returnType, targetType);
if (inferenceVariable != null) {
final PsiSubstitutor substitutor = resolveSubset(Collections.singletonList(inferenceVariable), mySiteSubstitutor);
myConstraints.add(new TypeCompatibilityConstraint(targetType, PsiUtil.captureToplevelWildcards(substitutor.substitute(inferenceVariable.getParameter()), myContext)));
final PsiType substitutedReturnType = substitutor.substitute(inferenceVariable.getParameter());
if (substitutedReturnType != null) {
myConstraints.add(new TypeCompatibilityConstraint(targetType, PsiUtil.captureToplevelWildcards(substitutedReturnType, myContext)));
}
}
else {
if (FunctionalInterfaceParameterizationUtil.isWildcardParameterized(returnType)) {
@@ -707,7 +710,7 @@ public class InferenceSession {
substitutor = substitutor.put(typeParameter, runtimeException);
}
else {
substitutor = substitutor.put(typeParameter, getUpperBound(var, substitutor));
substitutor = substitutor.put(typeParameter, myErased ? null : getUpperBound(var, substitutor));
}
}
@@ -0,0 +1,9 @@
import java.util.Collection;
abstract class NCollections {
public <T> void foo(Collection<? extends T> coll) {
bar((Collection)coll);
}
public abstract <T2 extends Object & Comparable<? super T2>> T2 bar(Collection<? extends T2> coll);
}
@@ -752,7 +752,9 @@ public class GenericsHighlighting8Test extends LightDaemonAnalyzerTestCase {
}
public void testSuperWildcardWithBoundPromotion() { doTest();}
public void testErasure() throws Exception { doTest(); }
private void doTest() {
doTest(false);
}