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

4.5: Possibly modify well-formedness restriction for wildcards?

    Details

      Description

      JLS 4.5: "A parameterized type C<T1,...,Tn> is well-formed if ... When subjected to capture conversion (§5.1.10) resulting in the type C<X1,...,Xn>, each type argument Xi is a subtype of S[F1:=X1,...,Fn:=Xn] for each bound type S in Bi. It is a compile-time error if a parameterized type is not well-formed."

      javac does not enforce the restriction. Instead, it checks the wildcard bound directly against the declaration-site bound (see checkExtends in Check.java). For upper bounds, this involves a castability check. For lower bounds, this involves a novel check called 'notSoftSubtypes'.

      Questions:

      - There are types that pass the javac check but not the JLS capture check. If we allow these types to be considered valid, what happens when they actually get captured somewhere downstream? Are we violating invariants of the type checker?

      - Are there any types that pass the JLS capture check but not the javac check? If so, are there good reasons to prohibit them?

      This bug may be resolved by updating JLS, producing a new bug requiring javac to conform to JLS, or some of both.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated: