Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2013-11-14 22:56:21 +0000
committerStephan Herrmann2013-11-19 11:51:02 +0000
commit8780bcc98bb34e217665d5c7db58c7a802aec2e5 (patch)
tree75e6943c961733c3caecfae830a3e3b057efacab
parentc4a1d1b76a7c1be4b1a021a2b31798b4e01629d3 (diff)
downloadeclipse.jdt.core-8780bcc98bb34e217665d5c7db58c7a802aec2e5.tar.gz
eclipse.jdt.core-8780bcc98bb34e217665d5c7db58c7a802aec2e5.tar.xz
eclipse.jdt.core-8780bcc98bb34e217665d5c7db58c7a802aec2e5.zip
implement "input variables" and "output variables"
implement reduce for type eq of non-wildcard types partly implement inferInvocationType() (needs pertinent to applicab.) tentatively improve isPolyExpression()
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java5
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java2
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java24
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ConstraintExceptionFormula.java52
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ConstraintExpressionFormula.java65
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ConstraintFormula.java18
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ConstraintTypeFormula.java13
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceContext18.java57
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceVariable.java6
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedGenericMethodBinding.java21
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedTypeBinding.java13
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java10
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeVariableBinding.java20
13 files changed, 274 insertions, 32 deletions
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java
index 17069c3f44..7539a3afb6 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java
@@ -1165,6 +1165,11 @@ public void tagAsEllipsisArgument() {
public boolean isPolyExpression() throws UnsupportedOperationException {
return false;
}
+/** Variant of isPolyExpression() to be used during type inference, when a resolution candidate exists. */
+public boolean isPolyExpression(MethodBinding method) {
+ return false;
+}
+
public void tagAsNeedCheckCast() {
// do nothing by default
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java
index ff1379a8d3..b2c07e707c 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java
@@ -288,7 +288,7 @@ public class LambdaExpression extends FunctionalExpression implements ReferenceC
return this.resolvedType;
}
- private boolean argumentsTypeElided() {
+ public boolean argumentsTypeElided() {
return this.arguments.length > 0 && this.arguments[0].hasElidedType();
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java
index 993b91f15d..ac980e3fe2 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java
@@ -60,9 +60,9 @@ import org.eclipse.jdt.internal.compiler.impl.ReferenceContext;
import org.eclipse.jdt.internal.compiler.lookup.Binding;
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
-import org.eclipse.jdt.internal.compiler.lookup.InferenceContext18;
-import org.eclipse.jdt.internal.compiler.lookup.ImplicitNullAnnotationVerifier;
import org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
+import org.eclipse.jdt.internal.compiler.lookup.ImplicitNullAnnotationVerifier;
+import org.eclipse.jdt.internal.compiler.lookup.InferenceContext18;
import org.eclipse.jdt.internal.compiler.lookup.InvocationSite;
import org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding;
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
@@ -861,16 +861,18 @@ public void setExpectedType(TypeBinding expectedType) {
public void setExpressionContext(ExpressionContext context) {
this.expressionContext = context;
}
-
public boolean isPolyExpression() {
-
/* 15.12 has four requirements: 1) The invocation appears in an assignment context or an invocation context
2) The invocation elides NonWildTypeArguments 3) the method to be invoked is a generic method (8.4.4).
4) The return type of the method to be invoked mentions at least one of the method's type parameters.
We are in no position to ascertain the last two until after resolution has happened. So no client should
depend on asking this question before resolution.
- */
+ */
+ return isPolyExpression(this.binding);
+}
+/** Variant of isPolyExpression() to be used during type inference, when a resolution candidate exists. */
+public boolean isPolyExpression(MethodBinding resolutionCandidate) {
if (this.expressionContext != ASSIGNMENT_CONTEXT && this.expressionContext != INVOCATION_CONTEXT)
return false;
@@ -880,9 +882,15 @@ public boolean isPolyExpression() {
if (this.constant != Constant.NotAConstant)
throw new UnsupportedOperationException("Unresolved MessageSend can't be queried if it is a polyexpression"); //$NON-NLS-1$
- if (this.binding != null && this.binding instanceof ParameterizedGenericMethodBinding) {
- ParameterizedGenericMethodBinding pgmb = (ParameterizedGenericMethodBinding) this.binding;
- return pgmb.inferredReturnType;
+ if (resolutionCandidate != null) {
+ if (resolutionCandidate instanceof ParameterizedGenericMethodBinding) {
+ ParameterizedGenericMethodBinding pgmb = (ParameterizedGenericMethodBinding) resolutionCandidate;
+ if (pgmb.inferredReturnType)
+ return true; // if already determined
+ }
+ if (resolutionCandidate.returnType != null) {
+ return resolutionCandidate.returnType.mentionsAny(resolutionCandidate.typeVariables(), -1);
+ }
}
return false;
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ConstraintExceptionFormula.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ConstraintExceptionFormula.java
index 121e1ee2a9..21195dddf6 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ConstraintExceptionFormula.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ConstraintExceptionFormula.java
@@ -14,6 +14,11 @@
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.lookup;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
import org.eclipse.jdt.internal.compiler.ast.ConditionalExpression;
import org.eclipse.jdt.internal.compiler.ast.Expression;
import org.eclipse.jdt.internal.compiler.ast.LambdaExpression;
@@ -48,4 +53,51 @@ public class ConstraintExceptionFormula extends ConstraintFormula {
return TRUE;
}
+ Collection inputVariables(final InferenceContext18 context) {
+ // from 18.5.2.
+ if (this.left instanceof LambdaExpression) {
+ if (this.right instanceof InferenceVariable) {
+ return Collections.singletonList(this.right);
+ }
+ if (this.right.isFunctionalInterface(context.scope)) {
+ LambdaExpression lambda = (LambdaExpression) this.left;
+ MethodBinding sam = this.right.getSingleAbstractMethod(context.scope); // TODO derive with target type?
+ final Set variables = new HashSet();
+ if (lambda.argumentsTypeElided()) {
+ // i)
+ int len = sam.parameters.length;
+ for (int i = 0; i < len; i++) {
+ sam.parameters[i].collectInferenceVariables(variables);
+ }
+ }
+ if (sam.returnType != TypeBinding.VOID) {
+ // ii)
+ sam.returnType.collectInferenceVariables(variables);
+ }
+ return variables;
+ }
+ } else if (this.left instanceof ReferenceExpression) {
+ if (this.right instanceof InferenceVariable) {
+ return Collections.singletonList(this.right);
+ }
+ if (this.right.isFunctionalInterface(context.scope)) { // TODO: && this.left is inexact
+ MethodBinding sam = this.right.getSingleAbstractMethod(context.scope); // TODO derive with target type?
+ final Set variables = new HashSet();
+ int len = sam.parameters.length;
+ for (int i = 0; i < len; i++) {
+ sam.parameters[i].collectInferenceVariables(variables);
+ }
+ sam.returnType.collectInferenceVariables(variables);
+ return variables;
+ }
+ } else if (this.left instanceof ConditionalExpression && this.left.isPolyExpression()) {
+ ConditionalExpression expr = (ConditionalExpression) this.left;
+ Set variables = new HashSet();
+ variables.addAll(new ConstraintExceptionFormula(expr.valueIfTrue, this.right).inputVariables(context));
+ variables.addAll(new ConstraintExceptionFormula(expr.valueIfFalse, this.right).inputVariables(context));
+ return variables;
+ }
+ return EMPTY_VARIABLE_LIST;
+ }
+
}
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 f136c9fccc..a93d1c87ce 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
@@ -14,11 +14,19 @@
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.lookup;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.jdt.internal.compiler.ASTVisitor;
import org.eclipse.jdt.internal.compiler.ast.ConditionalExpression;
import org.eclipse.jdt.internal.compiler.ast.Expression;
import org.eclipse.jdt.internal.compiler.ast.LambdaExpression;
import org.eclipse.jdt.internal.compiler.ast.MessageSend;
import org.eclipse.jdt.internal.compiler.ast.ReferenceExpression;
+import org.eclipse.jdt.internal.compiler.ast.ReturnStatement;
+import org.eclipse.jdt.internal.compiler.ast.Statement;
/**
* Implementation of 18.1.2 in JLS8, case:
@@ -167,6 +175,63 @@ class ConstraintExpressionFormula extends ConstraintFormula {
return null;
}
+ Collection inputVariables(final InferenceContext18 context) {
+ // from 18.5.2.
+ if (this.left instanceof LambdaExpression) {
+ if (this.right instanceof InferenceVariable) {
+ return Collections.singletonList(this.right);
+ }
+ if (this.right.isFunctionalInterface(context.scope)) {
+ LambdaExpression lambda = (LambdaExpression) this.left;
+ MethodBinding sam = this.right.getSingleAbstractMethod(context.scope); // TODO derive with target type?
+ final Set variables = new HashSet();
+ if (lambda.argumentsTypeElided()) {
+ // i)
+ int len = sam.parameters.length;
+ for (int i = 0; i < len; i++) {
+ sam.parameters[i].collectInferenceVariables(variables);
+ }
+ }
+ if (sam.returnType != TypeBinding.VOID) {
+ // ii)
+ final TypeBinding r = sam.returnType;
+ Statement body = lambda.body;
+ if (body instanceof Expression) {
+ variables.addAll(new ConstraintExpressionFormula((Expression) body, r, COMPATIBLE).inputVariables(context));
+ } else {
+ body.traverse(new ASTVisitor() {
+ public boolean visit(ReturnStatement returnStatement, BlockScope scope) {
+ variables.addAll(new ConstraintExpressionFormula(returnStatement.expression, r, COMPATIBLE).inputVariables(context));
+ return false;
+ }
+ }, (BlockScope)null);
+ }
+ }
+ return variables;
+ }
+ } else if (this.left instanceof ReferenceExpression) {
+ if (this.right instanceof InferenceVariable) {
+ return Collections.singletonList(this.right);
+ }
+ if (this.right.isFunctionalInterface(context.scope)) { // TODO: && this.left is inexact
+ MethodBinding sam = this.right.getSingleAbstractMethod(context.scope); // TODO derive with target type?
+ final Set variables = new HashSet();
+ int len = sam.parameters.length;
+ for (int i = 0; i < len; i++) {
+ sam.parameters[i].collectInferenceVariables(variables);
+ }
+ return variables;
+ }
+ } else if (this.left instanceof ConditionalExpression && this.left.isPolyExpression()) {
+ ConditionalExpression expr = (ConditionalExpression) this.left;
+ Set variables = new HashSet();
+ variables.addAll(new ConstraintExpressionFormula(expr.valueIfTrue, this.right, COMPATIBLE).inputVariables(context));
+ variables.addAll(new ConstraintExpressionFormula(expr.valueIfFalse, this.right, COMPATIBLE).inputVariables(context));
+ return variables;
+ }
+ return EMPTY_VARIABLE_LIST;
+ }
+
// debugging:
public String toString() {
StringBuffer buf = new StringBuffer().append('⟨');
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ConstraintFormula.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ConstraintFormula.java
index c372a4d2d0..cff19134a1 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ConstraintFormula.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ConstraintFormula.java
@@ -14,11 +14,19 @@
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.lookup;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
/**
* Implementation of 18.1.2 in JLS8
*/
abstract class ConstraintFormula extends ReductionResult {
+ static final List EMPTY_VARIABLE_LIST = Collections.EMPTY_LIST;
+
public abstract Object reduce(InferenceContext18 inferenceContext) throws InferenceFailureException;
/** 5.3: compatibility check which includes the option of boxing/unboxing. */
@@ -34,4 +42,14 @@ abstract class ConstraintFormula extends ReductionResult {
return false;
}
+ Collection inputVariables(InferenceContext18 context) {
+ return EMPTY_VARIABLE_LIST;
+ }
+
+ Collection outputVariables(InferenceContext18 context) {
+ Set variables = new HashSet();
+ this.right.collectInferenceVariables(variables);
+ variables.removeAll(inputVariables(context));
+ return variables;
+ }
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ConstraintTypeFormula.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ConstraintTypeFormula.java
index eb53abfb35..eab0078672 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ConstraintTypeFormula.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ConstraintTypeFormula.java
@@ -132,7 +132,18 @@ class ConstraintTypeFormula extends ConstraintFormula {
return new TypeBound((InferenceVariable) this.right, this.left, SAME);
}
if (TypeBinding.equalsEquals(this.left.original(), this.right.original())) {
- InferenceContext18.missingImplementation("NYI");
+ TypeBinding[] leftParams = this.left.typeArguments();
+ TypeBinding[] rightParams = this.right.typeArguments();
+ if (leftParams == null || rightParams == null)
+ return leftParams == rightParams ? TRUE : FALSE;
+ if (leftParams.length != rightParams.length)
+ return FALSE;
+ int len = leftParams.length;
+ ConstraintFormula[] constraints = new ConstraintFormula[len];
+ for (int i = 0; i < len; i++) {
+ constraints[i] = new ConstraintTypeFormula(leftParams[i], rightParams[i], SAME);
+ }
+ return constraints;
}
if (this.left.isArrayType() && this.right.isArrayType() && this.left.dimensions() == this.right.dimensions()) {
// checking dimensions already now is an optimization over reducing one dim at a time
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 0e3d199a8c..ee3c469c76 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
@@ -38,6 +38,11 @@ public class InferenceContext18 {
// interim, processed by createInitialConstraintsForParameters()
Expression[] invocationArguments;
+ // TODO make me an enum:
+ public static final int CHECK_STRICT = 1;
+ public static final int CHECK_LOOSE = 2;
+ public static final int CHECK_VARARG = 3;
+
/** Construct an inference context for an invocation (method/constructor). */
public InferenceContext18(Scope scope, Expression[] arguments) {
this.scope = scope;
@@ -137,8 +142,46 @@ public class InferenceContext18 {
}
/** JLS 18.5.2 Invocation Type Inference */
- public boolean inferPolyInvocationType(InvocationSite invocationSite, MethodBinding method) throws InferenceFailureException {
- return ConstraintExpressionFormula.inferPolyInvocationType(this, invocationSite, method);
+ public BoundSet inferInvocationType(TypeBinding expectedType, InvocationSite invocationSite, MethodBinding method, int checkKind)
+ throws InferenceFailureException
+ {
+ if (expectedType != null
+ && expectedType != TypeBinding.VOID
+ && invocationSite instanceof Expression
+ && ((Expression)invocationSite).isPolyExpression(method))
+ {
+ if (!ConstraintExpressionFormula.inferPolyInvocationType(this, invocationSite, method)) {
+ return null;
+ }
+ }
+ TypeBinding[] fs;
+ Expression[] arguments = this.invocationArguments;
+ if (arguments != null) {
+ int k = arguments.length;
+ switch (checkKind) {
+ case CHECK_STRICT:
+ case CHECK_LOOSE:
+ fs = method.parameters;
+ break;
+ case CHECK_VARARG:
+ fs = varArgTypes(method.parameters, k);
+ break;
+ default:
+ throw new IllegalStateException("Unexpected checkKind "+checkKind); //$NON-NLS-1$
+ }
+ for (int i = 0; i < k; i++) {
+// TypeBinding substF = substitute(fs[i]);
+// FIXME: need "pertinent to applicability"
+// // For all i (1 ≤ i ≤ k), if ei is not pertinent to applicability, the set contains ⟨ei → θ Fi⟩.
+// if (!this.currentBounds.reduceOneConstraint(this, new ConstraintExpressionFormula(arguments[i], substF, ReductionResult.COMPATIBLE)))
+// return false;
+
+ if (!this.currentBounds.reduceOneConstraint(this, new ConstraintExceptionFormula(arguments[i], expectedType))) // FIXME: spec says T, we use expectedType, OK?
+ return null;
+ }
+ }
+ // TODO 18.5.2 bullets 5ff.
+ return solve();
}
/** 18.5.2: before Invocation Type Inference purge all instantiations.
@@ -375,6 +418,16 @@ public class InferenceContext18 {
return numUninstantiated;
}
+ private TypeBinding[] varArgTypes(TypeBinding[] parameters, int k) {
+ TypeBinding[] types = new TypeBinding[k];
+ int declaredLength = parameters.length;
+ System.arraycopy(parameters, 0, types, 0, declaredLength);
+ TypeBinding last = parameters[declaredLength-1];
+ for (int i = declaredLength; i < k; i++)
+ types[i] = last;
+ return types;
+ }
+
// debugging:
public String toString() {
StringBuffer buf = new StringBuffer("Inference Context"); //$NON-NLS-1$
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceVariable.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceVariable.java
index f27588fadb..46e15c4c36 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceVariable.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceVariable.java
@@ -14,6 +14,8 @@
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.lookup;
+import java.util.Set;
+
import org.eclipse.jdt.core.compiler.CharOperation;
/**
@@ -56,6 +58,10 @@ public class InferenceVariable extends TypeVariableBinding {
return this;
}
+ void collectInferenceVariables(Set variables) {
+ variables.add(this);
+ }
+
public char[] qualifiedSourceName() {
throw new UnsupportedOperationException();
}
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 95aedf2e14..88be2b9f74 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
@@ -19,7 +19,6 @@
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.lookup;
-import org.eclipse.jdt.internal.compiler.ast.Expression;
import org.eclipse.jdt.internal.compiler.ast.Wildcard;
/**
@@ -62,6 +61,7 @@ public class ParameterizedGenericMethodBinding extends ParameterizedMethodBindin
// 1.8
InferenceContext18 infCtx18 = invocationSite.inferenceContext(scope);
if (infCtx18 != null) {
+ int checkKind = InferenceContext18.CHECK_LOOSE; // FIXME
// 18.5.1 (Applicability):
infCtx18.inferInvocationApplicability(originalMethod, arguments);
try {
@@ -69,22 +69,11 @@ public class ParameterizedGenericMethodBinding extends ParameterizedMethodBindin
if (result != null /*&& infCtx18.isResolved(result)*/) { // FIXME(stephan): second condition breaks BatchCompilerTest.test032
// 18.5.2 (Invocation type):
BoundSet provisionalResult = infCtx18.purgeInstantiations();
- boolean hasReturnProblem = false;
TypeBinding expectedType = invocationSite.expectedType();
- if (expectedType != null
- && expectedType != TypeBinding.VOID
- && invocationSite instanceof Expression
- && ((Expression)invocationSite).isPolyExpression())
- {
- if (infCtx18.inferPolyInvocationType(invocationSite, originalMethod)) {
- result = infCtx18.solve();
- if (result == null) {
- hasReturnProblem = true;
- result = provisionalResult; // we prefer a type error regarding the return type over reporting no match at all
- }
- }
- // TODO 18.5.2 bullets 4ff.
- }
+ result = infCtx18.inferInvocationType(expectedType, invocationSite, originalMethod, checkKind);
+ boolean hasReturnProblem = result == null;
+ if (hasReturnProblem)
+ result = provisionalResult; // we prefer a type error regarding the return type over reporting no match at all
TypeBinding[] solutions = infCtx18.getSolutions(typeVariables, result);
if (solutions != null) {
ParameterizedGenericMethodBinding parameterizedMethod = scope.environment().createParameterizedGenericMethod(originalMethod, solutions);
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedTypeBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedTypeBinding.java
index 7b00d3d059..725fa4ce69 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedTypeBinding.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedTypeBinding.java
@@ -30,6 +30,7 @@
package org.eclipse.jdt.internal.compiler.lookup;
import java.util.List;
+import java.util.Set;
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
@@ -866,7 +867,7 @@ public class ParameterizedTypeBinding extends ReferenceBinding implements Substi
return this.memberTypes;
}
- boolean mentionsAny(TypeBinding[] parameters, int idx) {
+ public boolean mentionsAny(TypeBinding[] parameters, int idx) {
if (super.mentionsAny(parameters, idx))
return true;
if (this.arguments != null) {
@@ -879,6 +880,16 @@ public class ParameterizedTypeBinding extends ReferenceBinding implements Substi
return false;
}
+ void collectInferenceVariables(Set variables) {
+ if (this.arguments != null) {
+ int len = this.arguments.length;
+ for (int i = 0; i < len; i++) {
+ if (TypeBinding.notEquals(this.arguments[i], this))
+ this.arguments[i].collectInferenceVariables(variables);
+ }
+ }
+ }
+
/**
* @see org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding#methods()
*/
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java
index 1e379d6b94..f222bd43d5 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java
@@ -25,6 +25,7 @@
package org.eclipse.jdt.internal.compiler.lookup;
import java.util.List;
+import java.util.Set;
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.internal.compiler.ast.Wildcard;
@@ -590,7 +591,7 @@ public boolean isInterface() {
return false;
}
-public boolean isFunctionalInterface() {
+public boolean isFunctionalInterface(Scope scope) {
return false;
}
@@ -1452,13 +1453,18 @@ public boolean isUnresolvedType() {
}
/** Does this type mention any of the given type parameters, except the one at position 'idx'? */
-boolean mentionsAny(TypeBinding[] parameters, int idx) {
+public boolean mentionsAny(TypeBinding[] parameters, int idx) {
for (int i = 0; i < parameters.length; i++)
if (i != idx)
if (TypeBinding.equalsEquals(parameters[i], this))
return true;
return false;
}
+
+/** Collect all inference variables mentioned in this type into variables. */
+void collectInferenceVariables(Set variables) {
+ // nop
+}
/** Answer an additional bit characterizing this type, like {@link TypeIds#BitAutoCloseable}. */
public boolean hasTypeBit(int bit) {
return false;
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeVariableBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeVariableBinding.java
index 3db6c35dfa..f5f27d8ae1 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeVariableBinding.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeVariableBinding.java
@@ -27,6 +27,8 @@
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.lookup;
+import java.util.Set;
+
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.internal.compiler.ast.Annotation;
import org.eclipse.jdt.internal.compiler.ast.NullAnnotationMatching;
@@ -555,7 +557,7 @@ public class TypeVariableBinding extends ReferenceBinding {
return Binding.TYPE_PARAMETER;
}
- boolean mentionsAny(TypeBinding[] parameters, int idx) {
+ public boolean mentionsAny(TypeBinding[] parameters, int idx) {
if (this.inRecursiveFunction)
return false; // nothing seen
this.inRecursiveFunction = true;
@@ -575,6 +577,22 @@ public class TypeVariableBinding extends ReferenceBinding {
}
}
+ void collectInferenceVariables(Set variables) {
+ if (this.inRecursiveFunction)
+ return; // nothing seen
+ this.inRecursiveFunction = true;
+ try {
+ if (this.superclass != null)
+ this.superclass.collectInferenceVariables(variables);
+ if (this.superInterfaces != null)
+ for (int j = 0; j < this.superInterfaces.length; j++) {
+ this.superInterfaces[j].collectInferenceVariables(variables);
+ }
+ } finally {
+ this.inRecursiveFunction = false;
+ }
+ }
+
public TypeBinding[] otherUpperBounds() {
if (this.firstBound == null)
return Binding.NO_TYPES;

Back to the top