Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2017-04-14 13:37:43 +0000
committerStephan Herrmann2017-04-14 13:38:47 +0000
commit33c2bbf0853e7d7634881ee1cdbec339eec8d40e (patch)
tree25133279a65292ef70782d30bca08ab67a55fc7b
parent82a37a244511a78abb719184529dbacc5eee9f6c (diff)
downloadeclipse.jdt.core-33c2bbf0853e7d7634881ee1cdbec339eec8d40e.tar.gz
eclipse.jdt.core-33c2bbf0853e7d7634881ee1cdbec339eec8d40e.tar.xz
eclipse.jdt.core-33c2bbf0853e7d7634881ee1cdbec339eec8d40e.zip
Bug 484713: [1.8][inference] ProblemReporter.invalidMethod() mightI20170414-2000
swallow mandatory error in case of InvocationTypeInferenceFailure Change-Id: I2ec52d46f3e236374313dfc31f4337f15ecae693 Signed-off-by: Stephan Herrmann <stephan.herrmann@berlin.de>
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java35
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java10
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ConstraintExpressionFormula.java14
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceContext18.java3
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java10
5 files changed, 67 insertions, 5 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 5345775d7d..d5985f147a 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
@@ -8165,4 +8165,39 @@ public void testBug508834_comment0() {
"Type mismatch: cannot convert from List<Integer> to List<Object>\n" +
"----------\n");
}
+
+ public void test483952_bare () {
+ runNegativeTest(
+ new String[] {
+ "test/Test.java",
+ "package test;\n" +
+ "import java.util.function.Function;\n" +
+ "public class Test {\n" +
+ " void test1() {\n" +
+ " Function function = x -> x;\n" +
+ " String [] z = test2(function, \"\");\n" +
+ " }\n" +
+ " <T> T [] test2(Function<T, T> function, T t) {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}"
+
+ },
+ "----------\n" +
+ "1. WARNING in test\\Test.java (at line 5)\n" +
+ " Function function = x -> x;\n" +
+ " ^^^^^^^^\n" +
+ "Function is a raw type. References to generic type Function<T,R> should be parameterized\n" +
+ "----------\n" +
+ "2. WARNING in test\\Test.java (at line 6)\n" +
+ " String [] z = test2(function, \"\");\n" +
+ " ^^^^^^^^^^^^^^^^^^^\n" +
+ "Type safety: Unchecked invocation test2(Function, String) of the generic method test2(Function<T,T>, T) of type Test\n" +
+ "----------\n" +
+ "3. WARNING in test\\Test.java (at line 6)\n" +
+ " String [] z = test2(function, \"\");\n" +
+ " ^^^^^^^^\n" +
+ "Type safety: The expression of type Function needs unchecked conversion to conform to Function<String,String>\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 6478082e3e..f93b5980d1 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
@@ -9323,6 +9323,16 @@ public void test483952 () {
" Function function = x -> x;\n" +
" ^^^^^^^^\n" +
"Function is a raw type. References to generic type Function<T,R> should be parameterized\n" +
+ "----------\n" +
+ "2. WARNING in test\\Test.java (at line 7)\n" +
+ " String @Nullable [] z = test2(function, \"\");\n" +
+ " ^^^^^^^^^^^^^^^^^^^\n" +
+ "Type safety: Unchecked invocation test2(Function, String) of the generic method test2(Function<T,T>, T) of type Test\n" +
+ "----------\n" +
+ "3. WARNING in test\\Test.java (at line 7)\n" +
+ " String @Nullable [] z = test2(function, \"\");\n" +
+ " ^^^^^^^^\n" +
+ "Type safety: The expression of type Function needs unchecked conversion to conform to Function<String,String>\n" +
"----------\n");
}
public void test484055() {
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 81c449b858..65fc171f5d 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
@@ -383,8 +383,7 @@ class ConstraintExpressionFormula extends ConstraintFormula {
throw new InferenceFailureException("expression has no value"); //$NON-NLS-1$
if (inferenceContext.usesUncheckedConversion) {
- // spec says erasure, but we don't really have compatibility rules for erasure, use raw type instead:
- TypeBinding erasure = inferenceContext.environment.convertToRawType(returnType, false);
+ TypeBinding erasure = getRealErasure(returnType, inferenceContext.environment);
ConstraintTypeFormula newConstraint = ConstraintTypeFormula.create(erasure, targetType, COMPATIBLE);
return inferenceContext.reduceAndIncorporate(newConstraint);
}
@@ -446,6 +445,17 @@ class ConstraintExpressionFormula extends ConstraintFormula {
return true;
}
+ private static TypeBinding getRealErasure(TypeBinding type, LookupEnvironment environment) {
+ TypeBinding erasure = type.erasure();
+ // could still be / contain a generic type that needs to be converted to raw:
+ TypeBinding erasedLeaf = erasure.leafComponentType();
+ if (erasedLeaf.isGenericType())
+ erasedLeaf = environment.convertToRawType(erasedLeaf, false);
+ if (erasure.isArrayType())
+ return environment.createArrayType(erasedLeaf, erasure.dimensions());
+ return erasedLeaf;
+ }
+
Collection<InferenceVariable> inputVariables(final InferenceContext18 context) {
// from 18.5.2.
if (this.left instanceof LambdaExpression) {
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 0c581672d1..17d5b7e825 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
@@ -1640,7 +1640,8 @@ 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 && method.returnType instanceof ReferenceBinding) {
+ if (InferenceContext18.SIMULATE_BUG_JDK_8026527 && expectedType != null
+ && (method.returnType instanceof ReferenceBinding || method.returnType instanceof ArrayBinding)) {
if (method.returnType.erasure().isCompatibleWith(expectedType))
return method; // don't count as problem.
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
index d1b542d195..4046259fcc 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
@@ -4306,7 +4306,6 @@ public void invalidMethod(MessageSend messageSend, MethodBinding method, Scope s
return;
case ProblemReasons.InferredApplicableMethodInapplicable:
case ProblemReasons.InvocationTypeInferenceFailure:
- // FIXME(stephan): construct suitable message (https://bugs.eclipse.org/404675)
problemMethod = (ProblemMethodBinding) method;
shownMethod = problemMethod.closestMatch;
if (problemMethod.returnType == shownMethod.returnType) { //$IDENTITY-COMPARISON$
@@ -4318,8 +4317,15 @@ public void invalidMethod(MessageSend messageSend, MethodBinding method, Scope s
new String[] { typeArguments, String.valueOf(shownMethod.original().shortReadableName()) },
messageSend.sourceStart,
messageSend.sourceEnd);
+ } else {
+ // FIXME(stephan): turn into an exception once we are sure about this
+ this.handle(IProblem.GenericInferenceError,
+ new String[] { "Unknown error at invocation of "+String.valueOf(shownMethod.readableName())}, //$NON-NLS-1$
+ new String[] { "Unknown error at invocation of "+String.valueOf(shownMethod.shortReadableName())}, //$NON-NLS-1$
+ messageSend.sourceStart,
+ messageSend.sourceEnd);
}
- return; // funnily this can happen in a deeply nested call, because the inner lies by stealing its closest match and the outer does not know so. See GRT1_8.testBug430296
+ return;
}
TypeBinding shownMethodReturnType = shownMethod.returnType.capture(scope, messageSend.sourceStart, messageSend.sourceEnd);
this.handle(

Back to the top