eliminate wildcards elimination in flattening intersection types (IDEA-143194); fully follow specification in determining target type - javac would be fixed (JDK-8142876), eclipse already obeys the spec

This commit is contained in:
Anna Kozlova
2015-11-12 20:14:15 +01:00
parent 44f26da2bc
commit 03d4334430
5 changed files with 44 additions and 25 deletions
@@ -85,8 +85,7 @@ public class PsiIntersectionType extends PsiType.Stub {
for (PsiType existing : array) {
if (type != existing) {
final boolean allowUncheckedConversion = type instanceof PsiClassType && ((PsiClassType)type).isRaw();
if (TypeConversionUtil.isAssignable(type, existing, allowUncheckedConversion) ||
TypeConversionUtil.isAssignable(GenericsUtil.eliminateWildcards(type), GenericsUtil.eliminateWildcards(existing), allowUncheckedConversion)) {
if (TypeConversionUtil.isAssignable(type, existing, allowUncheckedConversion)) {
iterator.remove();
break;
}
@@ -177,16 +177,19 @@ public class FunctionalInterfaceParameterizationUtil {
for (int i = 0; i < parameters.length; i++) {
PsiType paramType = parameters[i];
if (paramType instanceof PsiWildcardType) {
final PsiType bound = GenericsUtil.eliminateWildcards(((PsiWildcardType)paramType).getBound(), false, false);
for (PsiClassType paramBound : typeParameters[i].getExtendsListTypes()) {
if (PsiPolyExpressionUtil.mentionsTypeParameters(paramBound, typeParametersSet)) {
return null;
}
}
final PsiType bound = ((PsiWildcardType)paramType).getBound();
if (((PsiWildcardType)paramType).isSuper()) {
newParameters[i] = bound;
}
else {
newParameters[i] = bound != null ? bound : PsiType.getJavaLangObject(psiClass.getManager(), psiClassType.getResolveScope());
for (PsiClassType paramBound : typeParameters[i].getExtendsListTypes()) {
if (!PsiPolyExpressionUtil.mentionsTypeParameters(paramBound, typeParametersSet)) {
newParameters[i] = GenericsUtil.getGreatestLowerBound(newParameters[i], paramBound);
}
newParameters[i] = GenericsUtil.getGreatestLowerBound(newParameters[i], paramBound);
}
}
} else {
@@ -0,0 +1,13 @@
import java.util.Map;
class Main {
public static <T extends Map<? extends String, ? extends String>> T test() {
return null;
}
public static void main(String[] args) {
Map<String, String> m = Main.test();
}
}
@@ -7,16 +7,16 @@ class SimpleDependency {
}
{
I<? extends String, ? extends String> k = () -> null;
I<? extends String, String> k1 = () -> null;
I<? extends List<String>, List<String>> k2 = () -> null;
I<? extends List<String>, ? extends List<String>> k3 = () -> null;
I<? extends String, ? extends String> k = <error descr="Cannot infer functional interface type">() -> null</error>;
I<? extends String, String> k1 = <error descr="Cannot infer functional interface type">() -> null</error>;
I<? extends List<String>, List<String>> k2 = <error descr="Cannot infer functional interface type">() -> null</error>;
I<? extends List<String>, ? extends List<String>> k3 = <error descr="Cannot infer functional interface type">() -> null</error>;
I<? extends List<? extends String>, ? extends List<String>> k4 = <error descr="Cannot infer functional interface type">() -> null</error>;
I<? extends List<? extends String>, List<? extends String>> k5 = () -> null;
I<? extends List<? extends String>, ? extends List<? extends String>> k6 = () -> null;
I<? extends List<? extends String>, List<? extends String>> k5 = <error descr="Cannot infer functional interface type">() -> null</error>;
I<? extends List<? extends String>, ? extends List<? extends String>> k6 = <error descr="Cannot infer functional interface type">() -> null</error>;
I<? super String, String> s = () -> null;
I<? super List<String>, List<? extends String>> s1 = () -> null;
I<? super String, String> s = <error descr="Cannot infer functional interface type">() -> null</error>;
I<? super List<String>, List<? extends String>> s1 = <error descr="Cannot infer functional interface type">() -> null</error>;
}
}
@@ -43,11 +43,11 @@ class ExtendsList {
I<? extends List<?>, String> e1 = <error descr="Cannot infer functional interface type">() -> null</error>;
I<? extends List<?>, ?> e2 = <error descr="Cannot infer functional interface type">() -> null</error>;
I<? extends List<String>, ? extends String> e3 = () -> null;
I<? extends List<String>, ? extends String> e3 = <error descr="Cannot infer functional interface type">() -> null</error>;
I<? extends List<? extends String>, ? extends String> e4 = <error descr="Cannot infer functional interface type">() -> null</error>;
I<? super List<String>, ? extends String> s1 = () -> null;
I<? super List<String>, String> s2 = () -> null;
I<? super List<String>, ? extends String> s1 = <error descr="Cannot infer functional interface type">() -> null</error>;
I<? super List<String>, String> s2 = <error descr="Cannot infer functional interface type">() -> null</error>;
}
}
@@ -63,8 +63,8 @@ class MultipleBounds {
I<? extends List<String>, ? extends String> e1 = <error descr="Cannot infer functional interface type">() -> null</error>;
I<? extends Comparable<String>, ? extends String> e2 = <error descr="Cannot infer functional interface type">() -> null</error>;
I<? extends LC<String>, ? extends String> e3 = () -> null;
I<? extends LC<String>, String> e4 = () -> null;
I<? extends LC<String>, ? extends String> e3 = <error descr="Cannot infer functional interface type">() -> null</error>;
I<? extends LC<String>, String> e4 = <error descr="Cannot infer functional interface type">() -> null</error>;
I<? extends LC<? extends String>, String> e5 = <error descr="Cannot infer functional interface type">() -> null</error>;
}
}
@@ -80,9 +80,9 @@ class FirstIndependentBound {
I<?, String> n = <error descr="Cannot infer functional interface type">() -> null</error>;
I<? extends List<String>, ? extends String> e1 = <error descr="Cannot infer functional interface type">() -> null</error>;
I<? extends Comparable<String>, ? extends String> e2 = () -> null;
I<? extends LC<String>, ? extends String> e3 = () -> null;
I<? extends LC<String>, String> e4 = () -> null;
I<? extends Comparable<String>, ? extends String> e2 = <error descr="Cannot infer functional interface type">() -> null</error>;
I<? extends LC<String>, ? extends String> e3 = <error descr="Cannot infer functional interface type">() -> null</error>;
I<? extends LC<String>, String> e4 = <error descr="Cannot infer functional interface type">() -> null</error>;
I<? extends LC<? extends String>, String> e5 = <error descr="Cannot infer functional interface type">() -> null</error>;
}
}
@@ -98,10 +98,10 @@ class SecondIndependentBound {
{
I<?, String> n = <error descr="Cannot infer functional interface type">() -> null</error>;
I<? extends List<String>, ? extends String> e1 = () -> null;
I<? extends List<String>, ? extends String> e1 = <error descr="Cannot infer functional interface type">() -> null</error>;
I<? extends Comparable<String>, ? extends String> e2 = <error descr="Cannot infer functional interface type">() -> null</error>;
I<? extends LC<String>, ? extends String> e3 = () -> null;
I<? extends LC<String>, String> e4 = () -> null;
I<? extends LC<String>, ? extends String> e3 = <error descr="Cannot infer functional interface type">() -> null</error>;
I<? extends LC<String>, String> e4 = <error descr="Cannot infer functional interface type">() -> null</error>;
I<? extends LC<? extends String>, String> e5 = <error descr="Cannot infer functional interface type">() -> null</error>;
I<? extends LC<? extends String>, ? extends String> e6 = <error descr="Cannot infer functional interface type">() -> null</error>;
}
@@ -331,6 +331,10 @@ public class GraphInferenceHighlightingTest extends LightDaemonAnalyzerTestCase
doTest();
}
public void testEliminateIntersectionTypeWildcardElimination() throws Exception {
doTest();
}
private void doTest() throws Exception {
doTest(false);
}