1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/javac/lambda/EffectivelyFinalTest.java Wed Apr 27 01:34:52 2016 +0800 1.3 @@ -0,0 +1,55 @@ 1.4 +/* 1.5 + * @test /nodynamiccopyright/ 1.6 + * @bug 7175538 8003280 1.7 + * @summary Add lambda tests 1.8 + * Integrate effectively final check with DA/DU analysis 1.9 + * @compile/fail/ref=EffectivelyFinalTest01.out -XDrawDiagnostics EffectivelyFinalTest.java 1.10 + * @compile/fail/ref=EffectivelyFinalTest02.out -source 7 -Xlint:-options -XDrawDiagnostics EffectivelyFinalTest.java 1.11 + */ 1.12 +class EffectivelyFinalTest { 1.13 + 1.14 + void m1(int x) { 1.15 + int y = 1; 1.16 + new Object() { { System.out.println(x+y); } }; //ok - both x and y are EF 1.17 + } 1.18 + 1.19 + void m2(int x) { 1.20 + int y; 1.21 + y = 1; 1.22 + new Object() { { System.out.println(x+y); } }; //ok - both x and y are EF 1.23 + } 1.24 + 1.25 + void m3(int x, boolean cond) { 1.26 + int y; 1.27 + if (cond) y = 1; 1.28 + new Object() { { System.out.println(x+y); } }; //error - y not DA 1.29 + } 1.30 + 1.31 + void m4(int x, boolean cond) { 1.32 + int y; 1.33 + if (cond) y = 1; 1.34 + else y = 2; 1.35 + new Object() { { System.out.println(x+y); } }; //ok - both x and y are EF 1.36 + } 1.37 + 1.38 + void m5(int x, boolean cond) { 1.39 + int y; 1.40 + if (cond) y = 1; 1.41 + y = 2; 1.42 + new Object() { { System.out.println(x+y); } }; //error - y not EF 1.43 + } 1.44 + 1.45 + void m6(int x) { 1.46 + new Object() { { System.out.println(x+1); } }; //error - x not EF 1.47 + x++; // Illegal: x is not effectively final. 1.48 + } 1.49 + 1.50 + void m7(int x) { 1.51 + new Object() { { System.out.println(x=1); } }; //error - x not EF 1.52 + } 1.53 + 1.54 + void m8() { 1.55 + int y; 1.56 + new Object() { { System.out.println(y=1); } }; //error - y not EF 1.57 + } 1.58 +}