Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2017-12-20 20:19:46 +0000
committerStephan Herrmann2017-12-20 20:19:46 +0000
commit741c38f23aadb65453a23c15bf6ed02794196201 (patch)
tree2b3c1f62c8e46bbab326dce674986a28af2f47ec
parentf3ecb10a921e623034fe2bb4884dab8e6f6a0a9e (diff)
downloadeclipse.jdt.core-741c38f23aadb65453a23c15bf6ed02794196201.tar.gz
eclipse.jdt.core-741c38f23aadb65453a23c15bf6ed02794196201.tar.xz
eclipse.jdt.core-741c38f23aadb65453a23c15bf6ed02794196201.zip
Bug 519147 - [1.8][inference] Unknown error during inferenceI20171222-2000I20171221-2000I20171220-2000
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java13
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java48
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java4
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceContext18.java7
4 files changed, 44 insertions, 28 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java
index 24d0f36eb3..74016a57b6 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java
@@ -39798,24 +39798,11 @@ public void test1142() {
"}\n", // =================
},
// compiler results
- this.complianceLevel < ClassFileConstants.JDK1_8 ?
"----------\n" + /* expected compiler log */
"1. ERROR in X.java (at line 5)\n" +
" return compound(asList(a, b));\n" +
" ^^^^^^^^\n" +
"The method compound(Iterable<? extends Comparator<? super T>>) in the type X is not applicable for the arguments (List<Comparator<? extends Object>>)\n" +
- "----------\n"
- // 1.8+ ATM, we generate an extra error due to inner poly expression evaluation.
- :"----------\n" +
- "1. ERROR in X.java (at line 5)\n" +
- " return compound(asList(a, b));\n" +
- " ^^^^^^^^\n" +
- "The method compound(Iterable<? extends Comparator<? super T>>) in the type X is not applicable for the arguments (List<Comparator<? extends Object>>)\n" +
- "----------\n" +
- "2. ERROR in X.java (at line 5)\n" +
- " return compound(asList(a, b));\n" +
- " ^^^^^^^^^^^^\n" +
- "Type mismatch: cannot convert from List<Comparator<? extends Object>> to Iterable<? extends Comparator<? super T>>\n" +
"----------\n",
// javac options
JavacTestOptions.JavacHasABug.JavacBug6573446 /* javac test options */);
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java
index 9b3498f19d..1f02db6f5b 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java
@@ -1235,12 +1235,7 @@ public void testBug425493() {
" ^^^^^^^^^^^^\n" +
"The method addAttribute(Test.Attribute<T>, T) in the type Test is not applicable for the arguments (Test.Attribute<capture#1-of ?>, capture#2-of ?)\n" +
"----------\n" +
- "2. ERROR in Test.java (at line 3)\n" +
- " addAttribute(java.util.Objects.requireNonNull(attribute, \"\"),\n" +
- " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
- "Type mismatch: cannot convert from Test.Attribute<capture#1-of ?> to Test.Attribute<T>\n" +
- "----------\n" +
- "3. ERROR in Test.java (at line 5)\n" +
+ "2. ERROR in Test.java (at line 5)\n" +
" addAttribute(attribute, attribute.getDefault());\n" +
" ^^^^^^^^^^^^\n" +
"The method addAttribute(Test.Attribute<T>, T) in the type Test is not applicable for the arguments (Test.Attribute<capture#3-of ?>, capture#4-of ?)\n" +
@@ -7011,11 +7006,6 @@ public void testBug502350() {
" Stuff.func(Comparator.naturalOrder());\n" +
" ^^^^\n" +
"The method func(Comparator<T>) in the type Stuff is not applicable for the arguments (Comparator<Comparable<Comparable<B>>>)\n" +
- "----------\n" +
- "2. ERROR in makeCompilerFreeze\\EclipseJava8Bug.java (at line 20)\n" +
- " Stuff.func(Comparator.naturalOrder());\n" +
- " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
- "Type mismatch: cannot convert from Comparator<Comparable<Comparable<B>>> to Comparator<T>\n" +
"----------\n"
);
}
@@ -8767,4 +8757,40 @@ public void testBug508834_comment0() {
"}\n"
});
}
+ public void testBug519147() {
+ runConformTest(
+ new String[] {
+ "Main.java",
+ "import java.util.HashMap;\n" +
+ "import java.util.HashSet;\n" +
+ "import java.util.Set;\n" +
+ "\n" +
+ "public class Main<MyKey, MyValue> {\n" +
+ "\n" +
+ " static class MyMap<K, V> extends HashMap<K, V> {\n" +
+ " public MyMap<K, V> putAllReturning(MyMap<K, V> c) { putAll(c); return this; }\n" +
+ " public MyMap<K, V> putReturning(K key, V value) { put(key, value); return this; }\n" +
+ " }\n" +
+ "\n" +
+ " public Main() {\n" +
+ " Set<MyValue> values = new HashSet<>(); // actually something better\n" +
+ " final MyMap<MyKey, MyValue> myMap =\n" +
+ " values.stream()\n" +
+ " .reduce(\n" +
+ " new MyMap<MyKey, MyValue>(),\n" +
+ " (map, value) -> {\n" +
+ " Set<MyKey> keys = new HashSet<>(); // actually something better\n" +
+ "\n" +
+ " return keys.stream()\n" +
+ " .reduce(\n" +
+ " map, // this would work syntactically: new MyMap<MyKey, MyValue>(),\n" +
+ " (map2, key) -> map2.putReturning(key, value),\n" +
+ " MyMap::putAllReturning);\n" +
+ " },\n" +
+ " MyMap::putAllReturning\n" +
+ " );\n" +
+ " }\n" +
+ "}\n"
+ });
+ }
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java
index 53d3894fd6..fe1e0b51c0 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java
@@ -6910,8 +6910,8 @@ public void test443467() throws Exception {
"----------\n" +
"1. ERROR in BuildIdeMain.java (at line 9)\n" +
" filter2.map(p -> new SimpleEntry<>(updateToFile.get(p), p->ideFiles.get(p)));\n" +
- " ^^^^^^^^^^^^^^^^^^\n" +
- "The target type of this expression must be a functional interface\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Cannot infer type arguments for SimpleEntry<>\n" +
"----------\n");
}
public void testBug445227() {
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceContext18.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceContext18.java
index 179de81182..7bf57931a0 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceContext18.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceContext18.java
@@ -1655,9 +1655,12 @@ public class InferenceContext18 {
* unless the given candidate is tolerable to be compatible with buggy javac.
*/
public MethodBinding getReturnProblemMethodIfNeeded(TypeBinding expectedType, MethodBinding method) {
- if (InferenceContext18.SIMULATE_BUG_JDK_8026527 && expectedType != null
+ if (InferenceContext18.SIMULATE_BUG_JDK_8026527 && expectedType != null
+ && !(method.original() instanceof SyntheticFactoryMethodBinding)
&& (method.returnType instanceof ReferenceBinding || method.returnType instanceof ArrayBinding)) {
- if (method.returnType.erasure().isCompatibleWith(expectedType))
+ if (!expectedType.isProperType(true))
+ return null; // not ready
+ if (this.environment.convertToRawType(method.returnType.erasure(), false).isCompatibleWith(expectedType))
return method; // don't count as problem.
}
/* We used to check if expected type is null and if so return method, but that is wrong - it injects an incompatible method into overload resolution.

Back to the top