langtools/test/tools/javac/foreach/7139681/T7139681pos.java
author mcimadamore
Thu, 06 Jun 2013 15:32:41 +0100
changeset 18379 8dd20756448c
permissions -rw-r--r--
7139681: Enhanced for loop: local variable scope inconsistent with JLS Summary: For-each loop variable is incorrectly visible from the for-each expression Reviewed-by: jjg, vromero
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18379
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
     1
/*
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
     4
 *
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
     7
 * published by the Free Software Foundation.
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
     8
 *
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
    13
 * accompanied this code).
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
    14
 *
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
    18
 *
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
    21
 * questions.
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
    22
 */
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
    23
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
    24
/*
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
    25
 * @test
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
    26
 * @bug 7139681
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
    27
 * @summary Enhanced for loop: local variable scope inconsistent with JLS
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
    28
 *
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
    29
 * @compile T7139681pos.java
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
    30
 */
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
    31
class T7139681pos {
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
    32
    int[] a;
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
    33
    Iterable<Integer> b;
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
    34
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
    35
    void testArray() {
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
    36
        for (int a : a) {
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
    37
            int a2 = a;
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
    38
        }
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
    39
    }
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
    40
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
    41
    void testIterable() {
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
    42
        for (Integer b : b) {
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
    43
            Integer b2 = b;
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
    44
        }
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
    45
    }
8dd20756448c 7139681: Enhanced for loop: local variable scope inconsistent with JLS
mcimadamore
parents:
diff changeset
    46
}