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

Raw inner class constructor ref should not perform diamond inference

    XMLWordPrintable

Details

    • behavioral
    • minimal
    • Programs that were rejected in the past will be accepted now
    • Other
    • Implementation

    Description

      Summary

      The javac compiler is not in sync with a section of the language specification. In particular it is not in sync with section "15.13.1 Compile-Time Declaration of a Method Reference" of JLSs 11, 17 and 18. This provokes that some programs that should be accepted according to the language spec are rejected by javac

      Problem

      javac is not in sync with section §15.13.1 of the JLSs 11, 17 and 18 specifications. In particular javac is doing diamond inference for constructor references qualified by a raw type even for cases when that raw type is a non-static member of a raw type. This provokes that acceptable programs according to the spec are rejected by javac. As an example this code:

      class Outer<T> {
          class Inner1 {}
          class Inner2<U> {}
      
          Supplier<Outer<T>.Inner2<String>> s4 = Outer.Inner2::new;
      }

      is being rejected by javac on the basis of failed diamond inference. The spec mandates that no diamond inference should occur in this case as Inner2 is an inner class of a raw type.

      Solution

      Synchronize javac with section §15.13.1 of the JLSs 11, 17 and 18 specifications.

      Specification

      Of interest for this CSR is section §15.13.1 of the JLSs 11, 17 and 18 specifications, titled: "Compile-Time Declaration of a Method Reference" in particular where it reads:

      • If the method reference expression has the form ClassType ::
        [TypeArguments] new , then the potentially applicable methods are a set of
        notional methods corresponding to the constructors of ClassType.
      
        If ClassType is a raw type, but is not a non- static member type of a raw type,
        the candidate notional member methods are those specified in §15.9.3 for a
        class instance creation expression that uses <> to elide the type arguments to a
        class. Otherwise, the candidate notional member methods are the constructors
        of ClassType, treated as if they were methods with return type ClassType.

      Attachments

        Issue Links

          Activity

            People

              vromero Vicente Arturo Romero Zaldivar
              dlsmith Dan Smith
              Jan Lahoda
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: