diff options
| author | Stephan Herrmann | 2014-02-18 10:52:46 +0000 |
|---|---|---|
| committer | Stephan Herrmann | 2014-02-18 10:52:46 +0000 |
| commit | b0e8687830f97b9ddeb50b010730e5d2fdfd5916 (patch) | |
| tree | e7babe4040b4c127e76903b191e93187f4eb8f5b | |
| parent | dd10489904dda11a1b9c522a71a4705b9646605e (diff) | |
| download | eclipse.jdt.core-b0e8687830f97b9ddeb50b010730e5d2fdfd5916.tar.gz eclipse.jdt.core-b0e8687830f97b9ddeb50b010730e5d2fdfd5916.tar.xz eclipse.jdt.core-b0e8687830f97b9ddeb50b010730e5d2fdfd5916.zip | |
Bug 428307 - [1.8][compiler] Compiler fails to compile AnnotatedElement
2 files changed, 40 insertions, 1 deletions
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 c0f8a96ca3..efe49b1e84 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 @@ -2349,4 +2349,32 @@ public void test428352b() { }, "13"); } +public void testBug428307() { + runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "import java.util.function.Function;\n" + + "import java.util.stream.*;\n" + + "\n" + + "interface Bar {\n" + + " Class<? extends Bar> type();\n" + + "}\n" + + "public class X {\n" + + " \n" + + " <T extends Bar> T[] test(Class<T> barClass, Stream<Bar> bars) {\n" + + " return get(bars.\n" + + " collect(Collectors.toMap(Bar::type,\n" + + " Function.identity(),\n" + + " ((first,second) -> first),\n" + + " HashMap::new)),\n" + + " barClass);\n" + + " }\n" + + " \n" + + " <A extends Bar> A[] get(Map<Class<? extends Bar>,Bar> m, Class<A> c) {\n" + + " return null;\n" + + " }\n" + + "}\n" + }); +} } diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ConstraintExpressionFormula.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ConstraintExpressionFormula.java index 8247ed75f2..147833153d 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ConstraintExpressionFormula.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ConstraintExpressionFormula.java @@ -60,6 +60,7 @@ class ConstraintExpressionFormula extends ConstraintFormula { public Object reduce(InferenceContext18 inferenceContext) throws InferenceFailureException { // JLS 18.2.1 + proper: if (this.right.isProperType(true)) { TypeBinding exprType = this.left.resolvedType; if (exprType == null) { @@ -81,7 +82,17 @@ class ConstraintExpressionFormula extends ConstraintFormula { } else if (this.left instanceof AllocationExpression && this.left.isPolyExpression()) { // half-resolved diamond has a resolvedType, but that may not be the final word, try one more step of resolution: MethodBinding binding = ((AllocationExpression) this.left).binding(this.right, false, null); - return (binding != null && binding.declaringClass.isCompatibleWith(this.right)) ? TRUE : FALSE; + return (binding != null && binding.declaringClass.isCompatibleWith(this.right, inferenceContext.scope)) ? TRUE : FALSE; + } else if (this.left instanceof Invocation && this.left.isPolyExpression()) { + Invocation invoc = (Invocation) this.left; + MethodBinding binding = invoc.binding(this.right, false, null); + if (binding instanceof ParameterizedGenericMethodBinding) { + ParameterizedGenericMethodBinding method = (ParameterizedGenericMethodBinding) binding; + InferenceContext18 leftCtx = invoc.getInferenceContext(method); + if (leftCtx.stepCompleted < InferenceContext18.TYPE_INFERRED) { + break proper; // fall through into nested inference below (not explicit in the spec!) + } + } } return FALSE; } |
