1 /*
 2  * @test /nodynamiccopyright/
 3  * @summary Verify that various errors related to __WithField operator are caught.
 4  * @compile/fail/ref=WithFieldOperatorTest.out -XDallowWithFieldOperator -XDrawDiagnostics -XDdev WithFieldOperatorTest.java
 5  */
 6 
 7 public class WithFieldOperatorTest {
 8     static int xs;
 9     int ifld;
10     class Y {}
11     public final primitive class V { int x = 10; }
12 
13     public final primitive class X {
14 
15         final int x;
16         final V v;
17 
18         X() {
19             x = 10;
20             v = V.default;
21         }
22 
23         X getX(int xVal, WithFieldOperatorTest wfot) {
24             X x = X.default;
25             x = __WithField(new Y(), null);  // not a variable at all.
26             x = __WithField(wfot.xs, 10); // not an instance field.
27             x = __WithField(wfot.ifld, 10); // not a field of value type
28             x = __WithField(xVal, xVal); // not a field
29             x = __WithField(this, this); // not a field
30             x = __WithField(X.this, this); // not a field
31             x = __WithField(x.x, 12.0); // float cannot be assigned to int
32             x = __WithField(x.v, null); // null cannot be assigned to value
33             return x;
34         }
35     }
36 }
37 
38 class WithFieldOperatorTest_aux {
39     void foo(WithFieldOperatorTest.X x) {
40         x = __WithField(x.x, 10); // outside the nest
41     }
42 }