|
1 /* |
|
2 * @test /nodynamiccopyright/ |
|
3 * @bug 7175538 8003280 |
|
4 * @summary Add lambda tests |
|
5 * Integrate effectively final check with DA/DU analysis |
|
6 * @compile/fail/ref=EffectivelyFinalTest01.out -XDrawDiagnostics EffectivelyFinalTest.java |
|
7 * @compile/fail/ref=EffectivelyFinalTest02.out -source 7 -Xlint:-options -XDrawDiagnostics EffectivelyFinalTest.java |
|
8 */ |
|
9 class EffectivelyFinalTest { |
|
10 |
|
11 void m1(int x) { |
|
12 int y = 1; |
|
13 new Object() { { System.out.println(x+y); } }; //ok - both x and y are EF |
|
14 } |
|
15 |
|
16 void m2(int x) { |
|
17 int y; |
|
18 y = 1; |
|
19 new Object() { { System.out.println(x+y); } }; //ok - both x and y are EF |
|
20 } |
|
21 |
|
22 void m3(int x, boolean cond) { |
|
23 int y; |
|
24 if (cond) y = 1; |
|
25 new Object() { { System.out.println(x+y); } }; //error - y not DA |
|
26 } |
|
27 |
|
28 void m4(int x, boolean cond) { |
|
29 int y; |
|
30 if (cond) y = 1; |
|
31 else y = 2; |
|
32 new Object() { { System.out.println(x+y); } }; //ok - both x and y are EF |
|
33 } |
|
34 |
|
35 void m5(int x, boolean cond) { |
|
36 int y; |
|
37 if (cond) y = 1; |
|
38 y = 2; |
|
39 new Object() { { System.out.println(x+y); } }; //error - y not EF |
|
40 } |
|
41 |
|
42 void m6(int x) { |
|
43 new Object() { { System.out.println(x+1); } }; //error - x not EF |
|
44 x++; // Illegal: x is not effectively final. |
|
45 } |
|
46 |
|
47 void m7(int x) { |
|
48 new Object() { { System.out.println(x=1); } }; //error - x not EF |
|
49 } |
|
50 |
|
51 void m8() { |
|
52 int y; |
|
53 new Object() { { System.out.println(y=1); } }; //error - y not EF |
|
54 } |
|
55 } |