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

javac inference seems to be capturing types incorrectly

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P3
    • 22
    • None
    • tools

    Description

      when compiling this code:

      import java.util.*;

      public class Test {
          private static <T> void arrayMethod(List<? super T>[] args) {
              listMethod(Arrays.asList(args));
          }

          private static <T> void listMethod(List<List<? super T>> list) {
          }
      }

      javac issues error:

      Test.java:5: error: method listMethod in class Test cannot be applied to given types;
              listMethod(Arrays.asList(args));
              ^
        required: List<List<? super T#1>>
        found: List<List<? super T#2>>
        reason: inference variable T#3 has incompatible bounds
          equality constraints: List<? super CAP#1>
          lower bounds: List<? super T#2>
        where T#1,T#2,T#3 are type-variables:
          T#1 extends Object declared in method <T#1>listMethod(List<List<? super T#1>>)
          T#2 extends Object declared in method <T#2>arrayMethod(List<? super T#2>[])
          T#3 extends Object declared in method <T#3>asList(T#3...)
        where CAP#1 is a fresh type-variable:
          CAP#1 extends Object super: T#2 from capture of ? super T#2
      1 error

      there seems to be a type capture out of place and probably not blessed by the spec

      Reported by Attila Kelemen, see discussion at: https://mail.openjdk.org/pipermail/compiler-dev/2023-August/024034.html

      Attachments

        Issue Links

          Activity

            People

              vromero Vicente Arturo Romero Zaldivar
              vromero Vicente Arturo Romero Zaldivar
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: