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

[lworld] Assorted issues in generics and inline interplay

    XMLWordPrintable

Details

    • Bug
    • Resolution: Not an Issue
    • P4
    • repo-valhalla
    • repo-valhalla
    • tools
    • generic
    • generic

    Description

      As of https://github.com/openjdk/valhalla/pull/32,

      we have pulled the plug from the internal/experimental option -XDallowGenericsOverValues

      Values are islands in the type system.

      This prevents a set of programs that used to compile earlier from compiling now.

      import java.util.Arrays;

      interface I {}

      public inline class X implements I {

          int x = 10;

          void problem_01() {
              X [] a1 = new X[0];
              X [] a2 = Arrays.copyOf(a1, a2.length, X[].class);
            
      /*
      error: incompatible types: inference variable T has incompatible bounds
              X [] a2 = Arrays.copyOf(a1, a2.length, X[].class);
                                               ^
          lower bounds: X,Object
          lower bounds: X$ref
        where T,U are type-variables:
          T extends Object declared in method <T,U>copyOf(U[],int,Class<? extends T[]>)
          U extends Object declared in method <T,U>copyOf(U[],int,Class<? extends T[]>)
      1 error
      */
          }

          void foo(Class<? extends I> p) {}

          void problem_02() {
              foo(X.class);
      /*
      error: incompatible types: Class<X> cannot be converted to Class<? extends I>
              foo(X.class);
      */
          }

          String data() {
              return null;
          }

          // Problem: 3, we infer a stream of X.ref's causing
          // the method reference to not type check.
          void unbound_lookup_with_projected_receiver() {
              X [] a = new X[0];
              Arrays.stream(a).map(X::data).filter(p -> p != null).forEach(System.out::println);
      /*
      error: incompatible types: invalid method reference
              Arrays.stream(a).map(X::data).filter(p -> p != null).forEach(System.out::println);
                                   ^
          method data in class X cannot be applied to given types
            required: no arguments
            found: X$ref
            reason: actual and formal argument lists differ in length
      */
          }

          void problem_04() {
      /*
          test/hotspot/jtreg/runtime/valhalla/valuetypes/UnsafeTest.java:125: warning: [removal] putObject(Object,long,Object) in Unsafe has been deprecated and marked for removal
                  U.putObject(v, off_o, List.of("Value1", "Value2", "Value3"));
                   ^
      /home/srikanth/valhalla/test/valhalla/test/hotspot/jtreg/runtime/valhalla/valuetypes/UnsafeTest.java:127: error: method valueHeaderSize in class Unsafe cannot be applied to given types;
                  U.putInt(v, off_v + off_i - U.valueHeaderSize(Value2.class), 999);
                                               ^
        required: Class<V>
        found: Class<Value2>
        reason: inference variable V has incompatible bounds
          equality constraints: Value2
          lower bounds: Object
        where V is a type-variable:
          V extends Object declared in method <V>valueHeaderSize(Class<V>)
      */
          }

          void problem_05() {
      /*
      test/hotspot/jtreg/compiler/valhalla/valuetypes/TestIntrinsics.java:119: error: incomparable types: Class<CAP#1> and Class<MyValue1$ref>
              boolean check2 = MyValue1.class.asIndirectType().getSuperclass() == MyValue1.ref.class;
                                                                               ^
        where CAP#1 is a fresh type-variable:
          CAP#1 extends Object super: MyValue1 from capture of ? super MyValue1
      */
          }

          public static void main(String [] args) {
          }
      }

      Attachments

        Activity

          People

            vromero Vicente Arturo Romero Zaldivar
            sadayapalam Srikanth Adayapalam (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: