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

Unexpected inferred type from wildcard subtyping constraint

XMLWordPrintable

      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>

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

              Created:
              Updated:
              Resolved: