Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2017-02-19 18:01:45 +0000
committerStephan Herrmann2017-02-22 00:37:10 +0000
commit51ed0947dc59c8e4cadd7d626d5ed089ccf3bd98 (patch)
tree51c94e995e013721ca52efc08f3ea87e4a1758d3
parent3c7ad5b4400646eecbc59446414808da11176f5f (diff)
downloadeclipse.jdt.core-51ed0947dc59c8e4cadd7d626d5ed089ccf3bd98.tar.gz
eclipse.jdt.core-51ed0947dc59c8e4cadd7d626d5ed089ccf3bd98.tar.xz
eclipse.jdt.core-51ed0947dc59c8e4cadd7d626d5ed089ccf3bd98.zip
Bug 511252: [1.8][compiler][inference] "Type mismatch" in eclipse 4.6.2,I20170222-2000
compiles with javac - replaced one unspeced tweak with a solution hinted at by Maurizio Change-Id: Ibd60aed3259981b99e5ec33b8090f97e75dc2aef
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceContext18.java26
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedGenericMethodBinding.java14
2 files changed, 10 insertions, 30 deletions
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 24a90f4b23..46d502480c 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
@@ -686,15 +686,6 @@ public class InferenceContext18 {
if (innerContext != null) {
MethodBinding shallowMethod = innerMethod.shallowOriginal();
- if (looksLikeVarargs(innerMethod, argumentTypes)) {
- InferenceContext18 varArgsCtx = invocation.freshInferenceContext(innerContext.scope); // start over
- varArgsCtx.inferenceKind = InferenceContext18.CHECK_VARARG;
- varArgsCtx.inferInvocationApplicability(shallowMethod, argumentTypes, shallowMethod.isConstructor());
- if (varArgsCtx.solve(true) != null) {
- varArgsCtx.stepCompleted = InferenceContext18.APPLICABILITY_INFERRED;
- innerContext = varArgsCtx;
- }
- }
innerContext.outerContext = this;
if (innerContext.stepCompleted < InferenceContext18.APPLICABILITY_INFERRED) // shouldn't happen, but let's play safe
innerContext.inferInvocationApplicability(shallowMethod, argumentTypes, shallowMethod.isConstructor());
@@ -717,22 +708,7 @@ public class InferenceContext18 {
return true;
}
- private boolean looksLikeVarargs(MethodBinding method, TypeBinding[] argumentTypes) {
- if (method.isVarargs()) {
- if (argumentTypes.length == 0)
- return true;
- TypeBinding lastArg = argumentTypes[argumentTypes.length-1];
- if (lastArg == null) // argument still has a PolyTypeBinding (which is not stored in a.resolvedType)?
- return true; // TODO: which way to interpret?
- if (!lastArg.isArrayType()) // TODO: what if argtype is ivar that should resolve to array??
- return true;
- // TODO: also consider (T[] ...)!
- TypeBinding lastParam = method.parameters[method.parameters.length-1];
- return !lastArg.isCompatibleWith(lastParam);
- }
- return false;
- }
-
+
protected int getInferenceKind(MethodBinding nonGenericMethod, TypeBinding[] argumentTypes) {
switch (this.scope.parameterCompatibilityLevel(nonGenericMethod, argumentTypes)) {
case Scope.AUTOBOX_COMPATIBLE:
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedGenericMethodBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedGenericMethodBinding.java
index b3ef98112a..c09a29c911 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedGenericMethodBinding.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedGenericMethodBinding.java
@@ -211,12 +211,14 @@ public class ParameterizedGenericMethodBinding extends ParameterizedMethodBindin
CompilerOptions compilerOptions = scope.compilerOptions();
boolean invocationTypeInferred = false;
boolean requireBoxing = false;
+ boolean allArgumentsAreProper = true;
// See if we should start in loose inference mode.
TypeBinding [] argumentsCopy = new TypeBinding[arguments.length];
for (int i = 0, length = arguments.length, parametersLength = parameters.length ; i < length; i++) {
TypeBinding parameter = i < parametersLength ? parameters[i] : parameters[parametersLength - 1];
final TypeBinding argument = arguments[i];
+ allArgumentsAreProper &= argument.isProperType(true);
if (argument.isPrimitiveType() != parameter.isPrimitiveType()) { // Scope.cCM incorrectly but harmlessly uses isBaseType which answers true for null.
argumentsCopy[i] = scope.environment().computeBoxingType(argument);
requireBoxing = true; // can't be strict mode, needs at least loose.
@@ -272,7 +274,7 @@ public class ParameterizedGenericMethodBinding extends ParameterizedMethodBindin
TypeBinding[] solutions = infCtx18.getSolutions(typeVariables, invocationSite, result);
if (solutions != null) {
methodSubstitute = scope.environment().createParameterizedGenericMethod(originalMethod, solutions, infCtx18.usesUncheckedConversion, hasReturnProblem);
- if (invocationSite instanceof Invocation)
+ if (invocationSite instanceof Invocation && allArgumentsAreProper)
infCtx18.forwardResults(result, (Invocation) invocationSite, methodSubstitute, expectedType);
try {
if (hasReturnProblem) { // illegally working from the provisional result?
@@ -292,10 +294,12 @@ public class ParameterizedGenericMethodBinding extends ParameterizedMethodBindin
methodSubstitute = new PolyParameterizedGenericMethodBinding(methodSubstitute);
}
} finally {
- if (invocationSite instanceof Invocation)
- ((Invocation) invocationSite).registerInferenceContext(methodSubstitute, infCtx18); // keep context so we can finish later
- else if (invocationSite instanceof ReferenceExpression)
- ((ReferenceExpression) invocationSite).registerInferenceContext(methodSubstitute, infCtx18); // keep context so we can finish later
+ if (allArgumentsAreProper) {
+ if (invocationSite instanceof Invocation)
+ ((Invocation) invocationSite).registerInferenceContext(methodSubstitute, infCtx18); // keep context so we can finish later
+ else if (invocationSite instanceof ReferenceExpression)
+ ((ReferenceExpression) invocationSite).registerInferenceContext(methodSubstitute, infCtx18); // keep context so we can finish later
+ }
}
return methodSubstitute;
}

Back to the top