Thu, 10 Oct 2013 14:58:04 +0200
8001931: The new build system whitespace cleanup
Reviewed-by: tbell, simonis, erikj
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * @test /nodynamiccopyright/ |
aoqi@0 | 3 | * @bug 8003280 |
aoqi@0 | 4 | * @summary Add lambda tests |
aoqi@0 | 5 | * Integrate efectively final check with DA/DU analysis |
aoqi@0 | 6 | * @compile/fail/ref=LambdaEffectivelyFinalTest.out -XDrawDiagnostics LambdaEffectivelyFinalTest.java |
aoqi@0 | 7 | */ |
aoqi@0 | 8 | class LambdaEffectivelyFinalTest { |
aoqi@0 | 9 | |
aoqi@0 | 10 | interface SAM { |
aoqi@0 | 11 | int m(); |
aoqi@0 | 12 | } |
aoqi@0 | 13 | |
aoqi@0 | 14 | void foo(LambdaEffectivelyFinalTest.SAM s) { } |
aoqi@0 | 15 | |
aoqi@0 | 16 | void m1(int x) { |
aoqi@0 | 17 | int y = 1; |
aoqi@0 | 18 | foo(() -> x+y); // Legal: x and y are both effectively final. |
aoqi@0 | 19 | } |
aoqi@0 | 20 | |
aoqi@0 | 21 | void m2(int x) { |
aoqi@0 | 22 | int y; |
aoqi@0 | 23 | y = 1; |
aoqi@0 | 24 | foo(() -> x+y); // Legal: x and y are both effectively final. |
aoqi@0 | 25 | } |
aoqi@0 | 26 | |
aoqi@0 | 27 | void m3(int x, boolean cond) { |
aoqi@0 | 28 | int y; |
aoqi@0 | 29 | if (cond) y = 1; |
aoqi@0 | 30 | foo(() -> x+y); // Illegal: y is effectively final, but not definitely assigned. |
aoqi@0 | 31 | } |
aoqi@0 | 32 | |
aoqi@0 | 33 | void m4(int x, boolean cond) { |
aoqi@0 | 34 | int y; |
aoqi@0 | 35 | if (cond) y = 1; |
aoqi@0 | 36 | else y = 2; |
aoqi@0 | 37 | foo(() -> x+y); // Legal: x and y are both effectively final. |
aoqi@0 | 38 | } |
aoqi@0 | 39 | |
aoqi@0 | 40 | void m5(int x, boolean cond) { |
aoqi@0 | 41 | int y; |
aoqi@0 | 42 | if (cond) y = 1; |
aoqi@0 | 43 | y = 2; |
aoqi@0 | 44 | foo(() -> x+y); // Illegal: y is not effectively final.t EF |
aoqi@0 | 45 | } |
aoqi@0 | 46 | |
aoqi@0 | 47 | void m6(int x) { |
aoqi@0 | 48 | foo(() -> x+1); |
aoqi@0 | 49 | x++; // Illegal: x is not effectively final. |
aoqi@0 | 50 | } |
aoqi@0 | 51 | |
aoqi@0 | 52 | void m7(int x) { |
aoqi@0 | 53 | foo(() -> x=1); // Illegal: x in the assignment does not denote a variable (see 6.5.6.1) |
aoqi@0 | 54 | } |
aoqi@0 | 55 | |
aoqi@0 | 56 | void m8() { |
aoqi@0 | 57 | int y; |
aoqi@0 | 58 | foo(() -> y=1); // Illegal: y in the assignment does not denote a variable (see 6.5.6.1) |
aoqi@0 | 59 | } |
aoqi@0 | 60 | } |