Class LambdaBodyConstraint
- All Implemented Interfaces:
Constraint,ReductionResult
Creating those constraints requires the type of each invocation in the lambda body, and
therefore the types of the lambda's parameters. For an implicitly typed lambda, a parameter's
type is the corresponding parameter type of the function type derived from the target type
T; while that type still mentions an inference variable, the parameter has no type yet. JLS
18.2.1 says that a constraint on an implicitly typed lambda whose function type has a parameter
type that is not a proper type "reduces to false", and notes that the condition "never arises in
practice" precisely because 18.5.2.2 resolves the constraint's input variables first.
This constraint is the placeholder that makes that ordering happen: its input variables are
the inference variables that the lambda's parameter types mention, so InvocationTypeInference.getB4(org.checkerframework.framework.util.typeinference8.bound.BoundSet, org.checkerframework.framework.util.typeinference8.constraint.ConstraintSet) resolves them
before reducing it, and reducing it then creates the body's constraints from parameter types that
are proper.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.checkerframework.framework.util.typeinference8.constraint.Constraint
Constraint.KindNested classes/interfaces inherited from interface org.checkerframework.framework.util.typeinference8.constraint.ReductionResult
ReductionResult.ReductionResultPair -
Field Summary
Fields inherited from class org.checkerframework.framework.util.typeinference8.constraint.TypeConstraint
derivation, parent, source, TFields inherited from interface org.checkerframework.framework.util.typeinference8.constraint.ReductionResult
UNCHECKED_CONVERSION -
Constructor Summary
ConstructorsConstructorDescriptionLambdaBodyConstraint(LambdaExpressionTree lambda, AbstractType t) Creates aLambdaBodyConstraint. -
Method Summary
Modifier and TypeMethodDescriptionbooleanFor lambda and method references constraints, input variables are roughly the inference variables mentioned by the function type's parameter types and return types.getKind()Returns the kind of constraint."The output variables of [expression] constraints are all inference variables mentioned by the type on the right-hand side of the constraint, T, that are not input variables."inthashCode()static booleanmustDefer(LambdaExpressionTree lambda, AbstractType t) Returns whether the constraints produced by the body oflambdamust be deferred, because the lambda's parameters do not have types yet.reduce(Java8InferenceContext context) Reduce this constraint; what this means depends on the kind of constraint.Methods inherited from class org.checkerframework.framework.util.typeinference8.constraint.TypeConstraint
applyInstantiations, constraintHistory, functionTypeParameterVariables, getInferenceVariables, getInputVariablesForExpression, getT
-
Constructor Details
-
LambdaBodyConstraint
Creates aLambdaBodyConstraint.- Parameters:
lambda- an implicitly typed lambda expressiont- the target type oflambda
-
-
Method Details
-
mustDefer
Returns whether the constraints produced by the body oflambdamust be deferred, because the lambda's parameters do not have types yet.This is the case when
lambdais implicitly typed and either the target typetis itself an inference variable, or the function type derived fromthas a parameter type that is not a proper type.- Parameters:
lambda- a lambda expression that is an argument of an invocation under inferencet- the target type oflambda- Returns:
- whether the constraints produced by the body of
lambdamust be deferred
-
getKind
Description copied from interface:ConstraintReturns the kind of constraint.- Returns:
- the kind of constraint
-
getInputVariables
For lambda and method references constraints, input variables are roughly the inference variables mentioned by the function type's parameter types and return types. For conditional expression constraints and switch expression constraints, input variables are the union of the input variables of its subexpressions. For all other constraints, no input variables exist.Defined in JLS section 18.5.2.2
The input variables are those that make the lambda's parameter types improper: the target type itself if it is an inference variable, and otherwise the inference variables mentioned by the function type's parameter types. These are the input variables that JLS 18.5.2.2 defines for the corresponding
<LambdaExpression -> T>constraint, restricted to the ones that the lambda's parameters depend on.- Specified by:
getInputVariablesin classTypeConstraint- Returns:
- input variables for this constraint
-
getOutputVariables
Description copied from class:TypeConstraint"The output variables of [expression] constraints are all inference variables mentioned by the type on the right-hand side of the constraint, T, that are not input variables."As defined in JLS section 18.5.2.2
- Specified by:
getOutputVariablesin classTypeConstraint- Returns:
- output variables for this constraint
-
reduce
Reduce this constraint; what this means depends on the kind of constraint. Reduction can produce new bounds and/or new constraints.Reduction is documented in JLS section 18.2
The lambda's parameter types are proper by now, so the body's additional argument constraints can be created.
- Parameters:
context- Java8InferenceContext- Returns:
- the result of reducing this constraint
-
equals
- Overrides:
equalsin classTypeConstraint
-
hashCode
public int hashCode()- Overrides:
hashCodein classTypeConstraint
-