Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2014-01-26 20:11:37 +0000
committerStephan Herrmann2014-01-26 20:12:02 +0000
commita40625e8b71686fab9f6c8b263e48ade1ab498db (patch)
tree84e4a8eb02c29ed470ccd8aad243e50fe69a23a1
parent1438111baa39ba1a30117b19ff4ad6ece4a69fe1 (diff)
downloadeclipse.jdt.core-a40625e8b71686fab9f6c8b263e48ade1ab498db.tar.gz
eclipse.jdt.core-a40625e8b71686fab9f6c8b263e48ade1ab498db.tar.xz
eclipse.jdt.core-a40625e8b71686fab9f6c8b263e48ade1ab498db.zip
Bug 426671 - [1.8][inference] inference cannot leverage information from
reference expression - part 1
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java49
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceContext18.java10
2 files changed, 55 insertions, 4 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 0cbb866648..f37732a773 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
@@ -19,7 +19,7 @@ import junit.framework.Test;
public class GenericsRegressionTest_1_8 extends AbstractRegressionTest {
static {
-// TESTS_NAMES = new String[] { "testBug426540" };
+// TESTS_NAMES = new String[] { "testBug426671b" };
// TESTS_NUMBERS = new int[] { 40, 41, 43, 45, 63, 64 };
// TESTS_RANGE = new int[] { 11, -1 };
}
@@ -1330,6 +1330,53 @@ public void testBug426540() {
"}\n"
});
}
+public void _testBug426671_full() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "import java.util.stream.Stream;\n" +
+ "import java.util.*;\n" +
+ "import static java.util.stream.Collectors.collectingAndThen;\n" +
+ "import static java.util.stream.Collectors.toList;\n" +
+ "public class X {\n" +
+ " void test() {\n" +
+ " Arrays.asList((List<Integer>) null).stream().collect(collectingAndThen(toList(), Collections::unmodifiableList))\n" +
+ " .remove(0);\n" +
+ " }\n" +
+ "}\n"
+ });
+}
+public void testBug426671b() {
+ runNegativeTest(
+ new String[] {
+ "Test.java",
+ "interface I<X,Y> {\n" +
+ " Y fun(X y);\n" +
+ "}\n" +
+ "public class Test {\n" +
+ " static <S> S id(S s) { return s; }\n" +
+ " void test() {\n" +
+ " m1(Test::id, \"Hi\");\n" +
+ " m2(Test::id, \"Hi\").toUpperCase();\n" +
+ " m3(Test::id, \"Hi\").toUpperCase();\n" +
+ " }\n" +
+ "\n" +
+ " <U,V> void m1(I<V,U> i, U u) { }\n" +
+ " <U,V> V m2(I<V,U> i, U u) {\n" +
+ " return null;\n" +
+ " }\n" +
+ " <U,V> V m3(I<U,V> i, U u) {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}"
+ },
+ "----------\n" +
+ "1. ERROR in Test.java (at line 8)\n" +
+ " m2(Test::id, \"Hi\").toUpperCase();\n" +
+ " ^^^^^^^^^^^\n" +
+ "The method toUpperCase() is undefined for the type Object\n" +
+ "----------\n");
+}
public void testBug426652() {
runConformTest(
new String[] {
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 d99cff4203..977de73c91 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
@@ -489,7 +489,7 @@ public class InferenceContext18 {
ParameterizedGenericMethodBinding methodToCheck = method;
boolean haveProperTargetType = targetType != null && targetType.isProperType(true);
- if (haveProperTargetType) {
+ if (haveProperTargetType || invocation.getExpressionContext() == ExpressionContext.VANILLA_CONTEXT) {
MethodBinding original = method.originalMethod;
Solution solution = (Solution) this.solutionsPerTargetType.get(targetType);
BoundSet result = solution != null ? solution.bounds : null;
@@ -935,9 +935,13 @@ public class InferenceContext18 {
TypeBinding targetType = site.invocationTargetType();
if (targetType == null || !targetType.isProperType(true)) {
if (site.getExpressionContext() == ExpressionContext.VANILLA_CONTEXT) {
- // in this case we don't yet have the solution, compute it now:
+ // in this case we may not yet have the solution(?, get or compute it now:
+ Solution solution = (Solution) this.solutionsPerTargetType.get(targetType);
try {
- bounds = inferInvocationType(this.currentBounds, null, site, method);
+ if (solution != null && solution.bounds != null)
+ bounds = solution.bounds;
+ else
+ bounds = inferInvocationType(this.currentBounds, null, site, method.shallowOriginal());
} catch (InferenceFailureException e) {
return false;
}

Back to the top