test/tools/javac/lambda/EffectivelyFinalTest.java

Tue, 12 Mar 2013 16:02:43 +0000

author
mcimadamore
date
Tue, 12 Mar 2013 16:02:43 +0000
changeset 1628
5ddecb91d843
parent 1415
01c9d4161882
child 2020
bb7271e64ef6
permissions
-rw-r--r--

8009545: Graph inference: dependencies between inference variables should be set during incorporation
Summary: Move all transitivity checks into the incorporation round
Reviewed-by: jjg

     1 /*
     2  * @test /nodynamiccopyright/
     3  * @bug 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 {
    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     }
    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     }
    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     }
    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     }
    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     }
    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     }
    47     void m7(int x) {
    48         new Object() { { System.out.println(x=1); } }; //error - x not EF
    49     }
    51     void m8() {
    52         int y;
    53         new Object() { { System.out.println(y=1); } }; //error - y not EF
    54     }
    55 }

mercurial