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

Lambda Spec: Perform appropriate substitutions on constraint target types in 18.5.2

    Details

    • Subcomponent:
    • Verification:
      Verified

      Description

      Reported by Stephan Herrmann:

      class A {}
      class B extends A { void bar() {} }
      public class X {
       public static void main(String[] argv) {
         someWithIndex(getList(), (B b) -> b.bar()); // HERE
       }
       interface ItemWithIndexVisitor<E> {
         public void visit(E item);
       }
       public static <G> void someWithIndex(List<G> list, ItemWithIndexVisitor<G> visitor) {}
       static <I extends A> List<I> getList() { return null; }
      }

      javac accepts this program, but I don't see how:

      During invocation type inference for the marked call I get the following:

      The set C contains:
       constraint1: ⟨getList() ⊆throws java.util.List<G#0>⟩
       constraint2: ⟨(B b) -> b.bar() ⊆throws X.ItemWithIndexVisitor<G#0>⟩

      Input variables:
       constraint1: none
       constraint2: none

      Output variables:
       constraint1: G#0
       constraint2: G#0

      No input-output dependencies, so both constraints are picked.

      The union of input variables is empty, nothing gets resolved nor substituted
      => constraints remain as given above.

      During reduction of constraint2 we fail because of the unsubstituted
      inference variable G#0.
      This happens at 18.2.5 bullet 3:
       one "of the function type's parameter types is not a proper type" -> FALSE

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved: