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

Incorrect error: incompatible types: cannot infer type-variable(s) T#1,CAP#1,T#2

    XMLWordPrintable

    Details

      Description

      Consider this code:
      -----
      import java.util.Collection;
      import java.util.List;

      public final class ModelUtils {

          public static void getNamespaceScope(Collection<? extends CharSequence> l) {
              getFirst(filter(l));
          }

          public static <T> T getFirst(Collection<? extends T> all) {
              return null;
          }

          public static <T extends CharSequence> T getFirst(Collection<T> allElements, String... elementName) {
              return null;
          }

          public static <T extends CharSequence> List<? extends T> filter(Collection<T> allElements) {
              return null;
          }

      }
      -----

      Compiling using langtools with fix for JDK-8044546 yields:
      -----
      $ javac ModelUtils.java
      ModelUtils.java:7: error: incompatible types: cannot infer type-variable(s) T#1,CAP#1,T#2
              getFirst(filter(l));
                      ^
          (argument mismatch; List<CAP#2> cannot be converted to Collection<? extends CAP#2>)
        where T#1,T#2 are type-variables:
          T#1 extends Object declared in method <T#1>getFirst(Collection<? extends T#1>)
          T#2 extends CharSequence declared in method <T#2>filter(Collection<T#2>)
        where CAP#1,CAP#2,CAP#3 are fresh type-variables:
          CAP#1 extends T#2 from capture of ? extends T#2
          CAP#2 extends CAP#3 from capture of ? extends T#2
          CAP#3 extends CharSequence from capture of ? extends CharSequence
      1 error
      -----

      Compiling using langtools before the fix for JDK-8044546 passes:

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              vromero Vicente Arturo Romero Zaldivar
              Reporter:
              jlahoda Jan Lahoda
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: