test/tools/javac/lambda/EffectivelyFinalTest.java

Thu, 02 Aug 2012 18:23:21 +0100

author
mcimadamore
date
Thu, 02 Aug 2012 18:23:21 +0100
changeset 1297
e5cf1569d3a4
child 1415
01c9d4161882
permissions
-rw-r--r--

7175538: Integrate efectively final check with DA/DU analysis
Summary: Allow generalized effectively-final analysis for all local variables
Reviewed-by: jjg, dlsmith

mcimadamore@1297 1 /*
mcimadamore@1297 2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
mcimadamore@1297 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
mcimadamore@1297 4 *
mcimadamore@1297 5 * This code is free software; you can redistribute it and/or modify it
mcimadamore@1297 6 * under the terms of the GNU General Public License version 2 only, as
mcimadamore@1297 7 * published by the Free Software Foundation.
mcimadamore@1297 8 *
mcimadamore@1297 9 * This code is distributed in the hope that it will be useful, but WITHOUT
mcimadamore@1297 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
mcimadamore@1297 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
mcimadamore@1297 12 * version 2 for more details (a copy is included in the LICENSE file that
mcimadamore@1297 13 * accompanied this code).
mcimadamore@1297 14 *
mcimadamore@1297 15 * You should have received a copy of the GNU General Public License version
mcimadamore@1297 16 * 2 along with this work; if not, write to the Free Software Foundation,
mcimadamore@1297 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
mcimadamore@1297 18 *
mcimadamore@1297 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
mcimadamore@1297 20 * or visit www.oracle.com if you need additional information or have any
mcimadamore@1297 21 * questions.
mcimadamore@1297 22 */
mcimadamore@1297 23
mcimadamore@1297 24 /*
mcimadamore@1297 25 * @test
mcimadamore@1297 26 * @summary Integrate efectively final check with DA/DU analysis
mcimadamore@1297 27 * @compile/fail/ref=EffectivelyFinalTest01.out -XDallowEffectivelyFinalInInnerClasses -XDrawDiagnostics EffectivelyFinalTest.java
mcimadamore@1297 28 * @compile/fail/ref=EffectivelyFinalTest02.out -source 7 -Xlint:-options -XDrawDiagnostics EffectivelyFinalTest.java
mcimadamore@1297 29 */
mcimadamore@1297 30 class EffectivelyFinalTest {
mcimadamore@1297 31
mcimadamore@1297 32 void m1(int x) {
mcimadamore@1297 33 int y = 1;
mcimadamore@1297 34 new Object() { { System.out.println(x+y); } }; //ok - both x and y are EF
mcimadamore@1297 35 }
mcimadamore@1297 36
mcimadamore@1297 37 void m2(int x) {
mcimadamore@1297 38 int y;
mcimadamore@1297 39 y = 1;
mcimadamore@1297 40 new Object() { { System.out.println(x+y); } }; //ok - both x and y are EF
mcimadamore@1297 41 }
mcimadamore@1297 42
mcimadamore@1297 43 void m3(int x, boolean cond) {
mcimadamore@1297 44 int y;
mcimadamore@1297 45 if (cond) y = 1;
mcimadamore@1297 46 new Object() { { System.out.println(x+y); } }; //error - y not DA
mcimadamore@1297 47 }
mcimadamore@1297 48
mcimadamore@1297 49 void m4(int x, boolean cond) {
mcimadamore@1297 50 int y;
mcimadamore@1297 51 if (cond) y = 1;
mcimadamore@1297 52 else y = 2;
mcimadamore@1297 53 new Object() { { System.out.println(x+y); } }; //ok - both x and y are EF
mcimadamore@1297 54 }
mcimadamore@1297 55
mcimadamore@1297 56 void m5(int x, boolean cond) {
mcimadamore@1297 57 int y;
mcimadamore@1297 58 if (cond) y = 1;
mcimadamore@1297 59 y = 2;
mcimadamore@1297 60 new Object() { { System.out.println(x+y); } }; //error - y not EF
mcimadamore@1297 61 }
mcimadamore@1297 62
mcimadamore@1297 63 void m6(int x) {
mcimadamore@1297 64 new Object() { { System.out.println(x+1); } }; //error - x not EF
mcimadamore@1297 65 x++;
mcimadamore@1297 66 }
mcimadamore@1297 67
mcimadamore@1297 68 void m7(int x) {
mcimadamore@1297 69 new Object() { { System.out.println(x=1); } }; //error - x not EF
mcimadamore@1297 70 }
mcimadamore@1297 71
mcimadamore@1297 72 void m8() {
mcimadamore@1297 73 int y;
mcimadamore@1297 74 new Object() { { System.out.println(y=1); } }; //error - y not EF
mcimadamore@1297 75 }
mcimadamore@1297 76 }

mercurial