Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2019-10-24 19:15:13 +0000
committerStephan Herrmann2019-10-24 19:16:55 +0000
commit813ec98c92f68db13e7a2878c71aba07c8f93493 (patch)
tree35cb98c2cf0ccedb06f87b10a21d57197c88e192
parentf178ea0c32cc749d2aa2615414008a6a522da301 (diff)
downloadeclipse.jdt.core-813ec98c92f68db13e7a2878c71aba07c8f93493.tar.gz
eclipse.jdt.core-813ec98c92f68db13e7a2878c71aba07c8f93493.tar.xz
eclipse.jdt.core-813ec98c92f68db13e7a2878c71aba07c8f93493.zip
Bug 552388 - Type argument containment is too lenient when checkingI20191024-1800
enclosing parameterized type Change-Id: I96f1c864ed1a249cd977d7658b7754f411f42715
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java82
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java4
2 files changed, 84 insertions, 2 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java
index ca24f35d93..d687cd1c4d 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java
@@ -6507,5 +6507,87 @@ public void testBug543526b() {
};
runner.runConformTest();
}
+public void testBug552388() {
+ runNegativeTest(
+ new String[] {
+ "A.java",
+ "import java.util.ArrayList;\n" +
+ "import java.util.List;\n" +
+ "\n" +
+ "public class A<T extends B> {\n" +
+ " protected List<C> list = new ArrayList<>();\n" +
+ "\n" +
+ " class C {}\n" +
+ "\n" +
+ " public void createIO() {\n" +
+ " A<? extends B> x = null;\n" +
+ " List<A<? extends B>.C> y = x.list;\n" +
+ " }\n" +
+ "}\n" +
+ "\n" +
+ "class B {\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in A.java (at line 11)\n" +
+ " List<A<? extends B>.C> y = x.list;\n" +
+ " ^^^^^^\n" +
+ "Type mismatch: cannot convert from List<A<capture#1-of ? extends B>.C> to List<A<? extends B>.C>\n" +
+ "----------\n");
+}
+public void testBug552388b() {
+ runNegativeTest(
+ new String[] {
+ "A.java",
+ "import java.util.*;\n" +
+ "class A<T> {\n" +
+ " class C {\n" +
+ " T f;\n" +
+ " }\n" +
+ " C c = new C();\n" +
+ " A(T t) {\n" +
+ " c = new C();\n" +
+ " c.f = t;\n" +
+ " }\n" +
+ " void foo(List<A<?>.C> list) {\n" +
+ " list.add(new A<String>(\"\").c);\n" +
+ " list.add(new A<Number>(3).c);\n" +
+ " }\n" +
+ " T test() {\n" +
+ " List<C> l = new ArrayList<>();\n" +
+ " foo(l);\n" +
+ " return l.get(0).f;\n" +
+ " }\n" +
+ " public static void main(String... args) {\n" +
+ "// Number n = new A<Number>(1).test();\n" +
+ "// System.out.print(n.intValue());\n" +
+ " Number n = new A<Number>(1).test2();\n" +
+ " System.out.print(n.intValue());\n" +
+ " }\n" +
+ " \n" +
+ " void foo2(List<A<?>> list) {\n" +
+ " list.add(new A<String>(\"\"));\n" +
+ " list.add(new A<Number>(3));\n" +
+ " }\n" +
+ " T test2() {\n" +
+ " List<A<T>> l = new ArrayList<>();\n" +
+ " foo2(l); \n" +
+ " return l.get(0).c.f;\n" +
+ " }\n" +
+ " \n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in A.java (at line 17)\n" +
+ " foo(l);\n" +
+ " ^^^\n" +
+ "The method foo(List<A<?>.C>) in the type A<T> is not applicable for the arguments (List<A<T>.C>)\n" +
+ "----------\n" +
+ "2. ERROR in A.java (at line 33)\n" +
+ " foo2(l); \n" +
+ " ^^^^\n" +
+ "The method foo2(List<A<?>>) in the type A<T> is not applicable for the arguments (List<A<T>>)\n" +
+ "----------\n");
+}
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java
index d1abf63711..645fd171f9 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2018 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -1355,7 +1355,7 @@ public boolean isTypeArgumentContainedBy(TypeBinding otherType) {
if (TypeBinding.notEquals(enclosing, otherEnclosing))
return false;
} else {
- if (!enclosing.isEquivalentTo(otherParamType.enclosingType()))
+ if (!enclosing.isTypeArgumentContainedBy(otherParamType.enclosingType()))
return false;
}
}

Back to the top