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

Unexpected inferred type from wildcard subtyping constraint

    Details

      Description

      This should compile, does not:

          interface I<X> {}
          <T> T make(I<T> ts) { return null; }
          <E extends CharSequence> E take(I<? extends E> arg) { return null; }

          void test(I<I<? extends String>> arg) {
              take(make(arg)).intern();
          }

      Inference succeeds, with E=CharSequence. The call to 'intern' then fails. Expected: infer E=String.

      Walking through expected inference behavior:

      Applicability inference for 'make':
      I<I<? extends String>> --> I<t>
      { t = I<? extends String> }

      Applicability inference for 'take':
      make(arg) --> I<? extends e>
      t --> I<? extends e>
      { t = I<? extends String>, t <: I<? extends e>, e <: CharSequence }

      Incorporation:
      I<? extends String> <: I<? extends e>
      { t = I<? extends String>, t <: I<? extends e>, String <: e, e <: CharSequence }

      Resolution:
      e = String, t = I<? extends String>

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                vromero Vicente Arturo Romero Zaldivar
                Reporter:
                dlsmith Dan Smith
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: