mcimadamore@1297: /* mcimadamore@1415: * @test /nodynamiccopyright/ mcimadamore@1415: * @bug 8003280 mcimadamore@1415: * @summary Add lambda tests mcimadamore@1415: * Integrate effectively final check with DA/DU analysis mcimadamore@1415: * @compile/fail/ref=EffectivelyFinalTest01.out -XDrawDiagnostics EffectivelyFinalTest.java mcimadamore@1297: * @compile/fail/ref=EffectivelyFinalTest02.out -source 7 -Xlint:-options -XDrawDiagnostics EffectivelyFinalTest.java mcimadamore@1297: */ mcimadamore@1297: class EffectivelyFinalTest { mcimadamore@1297: mcimadamore@1297: void m1(int x) { mcimadamore@1297: int y = 1; mcimadamore@1297: new Object() { { System.out.println(x+y); } }; //ok - both x and y are EF mcimadamore@1297: } mcimadamore@1297: mcimadamore@1297: void m2(int x) { mcimadamore@1297: int y; mcimadamore@1297: y = 1; mcimadamore@1297: new Object() { { System.out.println(x+y); } }; //ok - both x and y are EF mcimadamore@1297: } mcimadamore@1297: mcimadamore@1297: void m3(int x, boolean cond) { mcimadamore@1297: int y; mcimadamore@1297: if (cond) y = 1; mcimadamore@1297: new Object() { { System.out.println(x+y); } }; //error - y not DA mcimadamore@1297: } mcimadamore@1297: mcimadamore@1297: void m4(int x, boolean cond) { mcimadamore@1297: int y; mcimadamore@1297: if (cond) y = 1; mcimadamore@1297: else y = 2; mcimadamore@1297: new Object() { { System.out.println(x+y); } }; //ok - both x and y are EF mcimadamore@1297: } mcimadamore@1297: mcimadamore@1297: void m5(int x, boolean cond) { mcimadamore@1297: int y; mcimadamore@1297: if (cond) y = 1; mcimadamore@1297: y = 2; mcimadamore@1297: new Object() { { System.out.println(x+y); } }; //error - y not EF mcimadamore@1297: } mcimadamore@1297: mcimadamore@1297: void m6(int x) { mcimadamore@1297: new Object() { { System.out.println(x+1); } }; //error - x not EF mcimadamore@1415: x++; // Illegal: x is not effectively final. mcimadamore@1297: } mcimadamore@1297: mcimadamore@1297: void m7(int x) { mcimadamore@1297: new Object() { { System.out.println(x=1); } }; //error - x not EF mcimadamore@1297: } mcimadamore@1297: mcimadamore@1297: void m8() { mcimadamore@1297: int y; mcimadamore@1297: new Object() { { System.out.println(y=1); } }; //error - y not EF mcimadamore@1297: } mcimadamore@1297: }