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

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

mercurial