java.lang.Object
org.checkerframework.framework.util.typeinference8.constraint.TypeConstraint
org.checkerframework.framework.util.typeinference8.constraint.LambdaBodyConstraint
All Implemented Interfaces:
Constraint, ReductionResult

public class LambdaBodyConstraint extends TypeConstraint
The additional argument constraints (JLS 18.5.2.2) produced by the body of an implicitly typed lambda expression, deferred until the lambda's parameter types are known.

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.

  • Constructor Details

    • LambdaBodyConstraint

      public LambdaBodyConstraint(LambdaExpressionTree lambda, AbstractType t)
      Creates a LambdaBodyConstraint.
      Parameters:
      lambda - an implicitly typed lambda expression
      t - the target type of lambda
  • Method Details

    • mustDefer

      public static boolean mustDefer(LambdaExpressionTree lambda, AbstractType t)
      Returns whether the constraints produced by the body of lambda must be deferred, because the lambda's parameters do not have types yet.

      This is the case when lambda is implicitly typed and either the target type t is itself an inference variable, or the function type derived from t has a parameter type that is not a proper type.

      Parameters:
      lambda - a lambda expression that is an argument of an invocation under inference
      t - the target type of lambda
      Returns:
      whether the constraints produced by the body of lambda must be deferred
    • getKind

      public Constraint.Kind getKind()
      Description copied from interface: Constraint
      Returns the kind of constraint.
      Returns:
      the kind of constraint
    • getInputVariables

      public List<Variable> 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:
      getInputVariables in class TypeConstraint
      Returns:
      input variables for this constraint
    • getOutputVariables

      public List<Variable> 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:
      getOutputVariables in class TypeConstraint
      Returns:
      output variables for this constraint
    • reduce

      public ReductionResult reduce(Java8InferenceContext context)
      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

      public boolean equals(Object o)
      Overrides:
      equals in class TypeConstraint
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class TypeConstraint