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

type inference: javac is incorrectly applying capture conversion during incorporation

    XMLWordPrintable

Details

    • b13
    • 9
    • generic
    • generic

    Description

      ADDITIONAL SYSTEM INFORMATION :
      Ubuntu 18.04 LTS

      java version "10.0.1" 2018-04-17
      Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
      Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)



      A DESCRIPTION OF THE PROBLEM :
      First reported here: https://stackoverflow.com/questions/50928300

      Type inference for generics has changed between Java8 and Java9/10 breaking special-case usages e.g. of the hamcrest library. Workarounds seem generally possible by providing more type information.

      REGRESSION : Last worked in version 8u172

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Try to compile given code with javac from Java9/10.



      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Code compiles as it does in Java8.
      ACTUAL -
      Code does not compile, type errors like:


          Error:(21, 28) java: incompatible types: inference variable U has incompatible bounds
          equality constraints: com.Test.B<? super com.Test.D>
          upper bounds: com.Test.B<? super capture#1 of ? super com.Test.D>,java.lang.Object



      ---------- BEGIN SOURCE ----------
      class Test1 {
          class A<S> { } class B<S> { } class C<S> { } class D { }

          <T> A<B<? super T>> foo() { return null; }

          <U> C<U> bar(A<U> a1, A<? super U> a2) { return null; }

          C<B<? super D>> c = bar(foo(), foo());
      }


      class Test2 {
          class A<S> { } class B<S> { } class C<S> { } class D { }

          <T> A<B<? super T>> foo() { return null; }

          <U> C<U> bar(A<? super U> a) { return null; }

          C<B<? super D>> c = bar(foo());
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Provide more type information such as casting arguments.

      FREQUENCY : always


      Attachments

        1. Test1.java
          0.2 kB
        2. Test2.java
          0.2 kB

        Issue Links

          Activity

            People

              vromero Vicente Arturo Romero Zaldivar
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated: