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

Cannot access methods/fields of a captured type belonging to an intersection type


    • Subcomponent:
    • Resolved In Build:
    • CPU:
    • OS:
    • Verification:
      Not verified


      JLS 4.4 Type Variables says:
      The members of a type variable X with bound T & I1 ... In are the members of the intersection type (§4.9) T & I1 ... In appearing at the point where the type variable is declared.

      JLS 4.9 Intersection Types
      The values of an intersection type are those objects that are values of all of the types Ti, for 1in.

      The test below declares the generic method "static <W extends F & I2> void method(C<? extends W> arg)" ,
      where E - class, F - class that extends E and implements I1; I, I1 - interfaces;
      C - generic class that declares type variable <T extends E & I>.
      There occures a capture conversion from C<? extends W> to C<S>.

      According to 5.1.10 Capture Conversion:
      If Ti is a wildcard type argument of the form ? extends Bi, then Si is a fresh type variable whose upper bound is glb(Bi, Ui[A1 := S1, ..., An := Sn]) and whose lower bound is the null type, where glb(V1,... ,Vm) is V1 & ... & Vm.

      So, S has upper bound (E & I) & W.
      So, the values of S are those objects that are values of all of the types E, I, W.

      But test below fails.
      -----------------Test code------------------------
      import java.io.PrintStream;

      class E {}
      class F extends E implements I1 {}
      interface I {}
      interface I1 {}

      class G extends F implements I {}

      class C<T extends E & I> {
          T field;

      public class type15302 {
          public static void main(String argv[]) {
              System.exit(run(argv, System.out) + 95/*STATUS_TEMP*/);

          public static int run(String argv[], PrintStream out) {
              C<G> arg = new C<G>();
              arg.field = new G();
              return 0/*STATUS_PASSED*/;

          static <W extends F> void method(C<? extends W> arg) {
              F vf = arg.field;
              I vi = arg.field;
              I1 vi1 = arg.field;
              E ve = arg.field;
              W vt = arg.field;
      Information:Compilation completed with 4 errors and 0 warnings
      Information:4 errors
      Information:0 warnings
          Error:Error:line (29)incompatible types
      found : capture#955 of ? extends W
      required: javasoft.sqe.tests.lang.type153.type15302.F
          Error:Error:line (31)incompatible types
      found : capture#671 of ? extends W
      required: javasoft.sqe.tests.lang.type153.type15302.I1
          Error:Error:line (32)incompatible types
      found : capture#442 of ? extends W
      required: javasoft.sqe.tests.lang.type153.type15302.E
          Error:Error:line (33)incompatible types
      found : capture#274 of ? extends W
      required: W


          Issue Links



              • Assignee:
                mcimadamore Maurizio Cimadamore
                ynovozhi Yulia Novozhilova (Inactive)
              • Votes:
                0 Vote for this issue
                0 Start watching this issue


                • Created: