diamonds: do not capture wildcard on inference (IDEA-73689 )

This commit is contained in:
anna
2011-08-31 16:53:36 +02:00
parent 2583e0bc7b
commit ab1d2768b6
2 changed files with 22 additions and 14 deletions
@@ -97,14 +97,14 @@ interface I<T> {
class FI1 {
I<? extends String> i1 = new I<<error descr="Cannot use ''<>'' with anonymous inner classes"></error>>() {
@Override
public String m() {
public <error descr="'m()' in 'Anonymous class derived from I' clashes with 'm()' in 'I'; attempting to use incompatible return type">String</error> m() {
return null;
}
};
I<?> i2 = new I<<error descr="Cannot use ''<>'' with anonymous inner classes"></error>>() {
@Override
public Object m() {
public <error descr="'m()' in 'Anonymous class derived from I' clashes with 'm()' in 'I'; attempting to use incompatible return type">Object</error> m() {
return null;
}
};
@@ -152,4 +152,23 @@ class ParenthTest<T extends TZ> {
ParenthTest<T> x = (new ParenthTest<>(null)); //red code is here
return 1;
}
}
class TestWildcardInference {
interface A<T> {
}
class B<V> implements A<V> {
B(C<V> v) {
}
}
class C<E> {}
class U {
void foo() {
C<? extends Number> x = null;
A<? extends Number> y = new B<>(x);
}
}
}
@@ -295,18 +295,7 @@ public class PsiDiamondType extends PsiType {
if (myErrorMessage != null) {
return PsiType.EMPTY_ARRAY;
}
final PsiType[] result = new PsiType[myInferredTypes.size()];
for (int i = 0, myInferredTypesSize = myInferredTypes.size(); i < myInferredTypesSize; i++) {
PsiType inferredType = myInferredTypes.get(i);
if (inferredType instanceof PsiWildcardType) {
final PsiType bound = ((PsiWildcardType)inferredType).getBound();
result[i] = bound != null ? bound : PsiType.getJavaLangObject(PsiManager.getInstance(myProject), GlobalSearchScope.allScope(myProject));
}
else {
result[i] = inferredType;
}
}
return result;
return myInferredTypes.toArray(new PsiType[myInferredTypes.size()]);
}
/**