1 /*
  2  * @test /nodynamiccopyright/
  3  * @bug 8324873
  4  * @summary Permit additional statements before this/super in constructors
  5  * @compile/fail/ref=ValueClassSuperInitFails.out -XDrawDiagnostics ValueClassSuperInitFails.java
  6  * @enablePreview
  7  */
  8 
  9 abstract value class AR<V> implements java.io.Serializable {
 10     public AR(V initialValue) {
 11     }
 12 
 13     public AR() {
 14     }
 15 }
 16 
 17 value class ValueClassSuperInitFails extends AR <Object> implements Iterable<Object> {
 18 
 19     private int x;
 20 
 21 /// GOOD EXAMPLES
 22 
 23     public ValueClassSuperInitFails() {           // this should be OK
 24         // super()
 25     }
 26 
 27     public ValueClassSuperInitFails(Object x) {
 28         this.x = x.hashCode();          // this should be OK
 29         // super();  the compiler will introduce the super call at this location
 30     }
 31 
 32     public ValueClassSuperInitFails(byte x) {
 33         super();                        // this should be OK
 34     }
 35 
 36     public ValueClassSuperInitFails(char x) {
 37         this((int)x);                   // this should be OK
 38     }
 39 
 40 /// FAIL EXAMPLES
 41 
 42     {
 43         this(1);                        // this should FAIL
 44     }
 45 
 46     {
 47         super();                        // this should FAIL
 48     }
 49 
 50     void normalMethod1() {
 51         super();                        // this should FAIL
 52     }
 53 
 54     void normalMethod2() {
 55         this();                         // this should FAIL
 56     }
 57 
 58     void normalMethod3() {
 59         Runnable r = () -> super();     // this should FAIL
 60     }
 61 
 62     void normalMethod4() {
 63         Runnable r = () -> this();      // this should FAIL
 64     }
 65 
 66     public ValueClassSuperInitFails(short x) {
 67         hashCode();                     // this should FAIL
 68         //super();
 69     }
 70 
 71     public ValueClassSuperInitFails(float x) {
 72         this.hashCode();                // this should FAIL
 73         //super();
 74     }
 75 
 76     public ValueClassSuperInitFails(int x) {
 77         super.hashCode();               // this should FAIL
 78         //super();
 79     }
 80 
 81     public ValueClassSuperInitFails(long x) {
 82         ValueClassSuperInitFails.this.hashCode();      // this should FAIL
 83         //super();
 84     }
 85 
 86     public ValueClassSuperInitFails(double x) {
 87         ValueClassSuperInitFails.super.hashCode();     // this should FAIL
 88         //super();
 89     }
 90 
 91     public ValueClassSuperInitFails(byte[] x) {
 92         {
 93             super();                    // this should FAIL
 94         }
 95     }
 96 
 97     public ValueClassSuperInitFails(char[] x) {
 98         if (x.length == 0)
 99             return;                     // this should FAIL
100         //super();
101     }
102 
103     public ValueClassSuperInitFails(short[] x) {
104         this.x = x.length;              // this should be OK
105         //super();
106     }
107 
108     public ValueClassSuperInitFails(float[] x) {
109         System.identityHashCode(this);  // this should FAIL
110         //super();
111     }
112 
113     public ValueClassSuperInitFails(int[] x) {
114         this(this);                     // this should FAIL
115     }
116 
117     public ValueClassSuperInitFails(long[] x) {
118         this(Object.this);              // this should FAIL
119     }
120 
121     public ValueClassSuperInitFails(double[] x) {
122         Iterable.super.spliterator();   // this should FAIL
123         //super();
124     }
125 
126     public ValueClassSuperInitFails(byte[][] x) {
127         super(new Object() {
128             {
129                 super();                // this should FAIL
130             }
131         });
132     }
133 
134     public ValueClassSuperInitFails(char[][] x) {
135         new Inner1();                   // this should FAIL
136         //super();
137     }
138 
139     class Inner1 {
140     }
141 
142     record Record1(int value) {
143         Record1(float x) {              // this should FAIL
144         }
145     }
146 
147     record Record2(int value) {
148         Record2(float x) {              // this should FAIL
149             super();
150         }
151     }
152 
153     @Override
154     public java.util.Iterator<Object> iterator() {
155         return null;
156     }
157 
158     public ValueClassSuperInitFails(short[][] x) {
159         class Foo {
160             Foo() {
161                 ValueClassSuperInitFails.this.hashCode();
162             }
163         };
164         new Foo();                      // this should FAIL
165         //super();
166     }
167 
168     public ValueClassSuperInitFails(float[][] x) {
169         Runnable r = () -> {
170             super();                    // this should FAIL
171         };
172     }
173 
174     public ValueClassSuperInitFails(int[][] z) {
175         super((Runnable)() -> x);       // this should FAIL
176     }
177 
178     public ValueClassSuperInitFails(long[][] z) {
179         super(new Inner1());            // this should FAIL
180     }
181 }