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

Wrong Type-Argument inference in presence of bounds and use-site variance

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 11, 17, 18
    • tools
    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      The following example does not compile. If we explicitly define the type of variable x, then it works.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      javac Cls.java

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Compile successfully
      ACTUAL -
      Cls.java:23: error: incompatible types: Cls4<CAP#1> cannot be converted to Cls4<? extends Cls3<Float>>
          return x;
                 ^
        where CAP#1 is a fresh type-variable:
          CAP#1 extends Cls3<? super Float> from capture of ?
      1 error

      ---------- BEGIN SOURCE ----------
      abstract class Cls<T1> {
        public Cls() {}
      }

      abstract class Cls2<T2> extends Cls<T2> {
        public Cls2() {}
      }

      abstract class Cls3<T3 extends Float> extends Cls2<T3> {
        public Cls3() {}
      }

      abstract class Cls4<T4 extends Cls3<? super Float>> {
        public Cls4() {}
      }

      final class Cls5 {
        public Cls5() {}
        public final Cls4<? extends Cls3<Float>> foo() {
          Cls4<? extends Cls3<Float>> y = (Cls4<? extends Cls3<Float>>) null;
          var x = y;
          // Cls4<? extends Cls3<Float>> x = y; // This works
          return x;
        }
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


            adev Anupam Dev
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: