Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8038747

18.5.2: Consider lambdas appearing as nested invocation arguments inside other lambdas

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 8
    • Fix Version/s: 8u40
    • Component/s: specification
    • Labels:

      Description

      JDK-8033488 ensured that nested lambdas like the following are considered by the outer invocation's invocation type inference:

      foo(bar(x -> expr))

      However, it did not consider poly method invocations nested inside _other_ lambda expressions:

      foo(y -> bar(x -> expr))

      Assuming 'bar' is a poly method invocation, the lambda expression x->expr can impact the type arguments of 'foo', and thus should be considered as part of the set of constraints 'C', as described in 18.5.2.

      In general, we need to consider all lambda result expressions that are i) poly method invocations, ii) poly class instance creations, or iii) conditionals/parenthesizeds that wrap on of these.

        Issue Links

          Activity

          Hide
          dlsmith Dan Smith added a comment -
          Updated text for 18.5.2:

          ---
          For all i (1 ≤ i ≤ k), additional constraints may be included, depending on the
          form of ei:

          - If ei is a LambdaExpression, C contains ‹LambdaExpression →throws Fi θ›.

          ***
          In addition, the lambda body is searched for additional constraints:
          -- For a block lambda body, the search is applied recursively to each result expression.
          -- For a poly class instance creation expression (§15.9) or a poly method invocation expression (§15.12), C contains all the constraint formulas that would appear in the set C generated by §18.5.2 when inferring the poly expression's invocation type.
          -- For a parenthesized expression, the search is applied recursively to the contained expression.
          -- For a conditional expression, the search is applied recursively to the second and third operands.
          -- For a lambda expression, the search is applied recursively to the lambda body.
          ***

          - If ei is a MethodReference, C contains ‹MethodReference →throws Fi θ›.

          - If ei is a poly class instance creation expression (§15.9) or a poly method invocation expression (§15.12), C contains all the constraint formulas that would appear in the set C generated by §18.5.2 when inferring the poly expression's invocation type.

          - If ei is a parenthesized expression, these rules are applied recursively to the contained expression.

          - If ei is a conditional expression, these rules are applied recursively to the second and third operands.

          ---

          I note that there's a lot of "shared code" between these two pattern matches, but I'm not seeing a clean way to eliminate that redundancy. They are slightly different operations, even though they have a similar form.
          Show
          dlsmith Dan Smith added a comment - Updated text for 18.5.2: --- For all i (1 ≤ i ≤ k), additional constraints may be included, depending on the form of ei: - If ei is a LambdaExpression, C contains ‹LambdaExpression →throws Fi θ›. *** In addition, the lambda body is searched for additional constraints: -- For a block lambda body, the search is applied recursively to each result expression. -- For a poly class instance creation expression (§15.9) or a poly method invocation expression (§15.12), C contains all the constraint formulas that would appear in the set C generated by §18.5.2 when inferring the poly expression's invocation type. -- For a parenthesized expression, the search is applied recursively to the contained expression. -- For a conditional expression, the search is applied recursively to the second and third operands. -- For a lambda expression, the search is applied recursively to the lambda body. *** - If ei is a MethodReference, C contains ‹MethodReference →throws Fi θ›. - If ei is a poly class instance creation expression (§15.9) or a poly method invocation expression (§15.12), C contains all the constraint formulas that would appear in the set C generated by §18.5.2 when inferring the poly expression's invocation type. - If ei is a parenthesized expression, these rules are applied recursively to the contained expression. - If ei is a conditional expression, these rules are applied recursively to the second and third operands. --- I note that there's a lot of "shared code" between these two pattern matches, but I'm not seeing a clean way to eliminate that redundancy. They are slightly different operations, even though they have a similar form.

            People

            • Assignee:
              abuckley Alex Buckley
              Reporter:
              dlsmith Dan Smith
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: