test/langtools/tools/javac/patterns/DuplicateBindingTest.java
author jlahoda
Wed, 27 Nov 2019 09:00:01 +0100
changeset 59285 7799a51dbe30
permissions -rw-r--r--
8231826: Implement javac changes for pattern matching for instanceof Reviewed-by: mcimadamore Contributed-by: brian.goetz@oracle.com, gavin.bierman@oracle.com, maurizio.cimadamore@oracle.com, srikanth.adayapalam@oracle.com, vicente.romero@oracle.com, jan.lahoda@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
59285
7799a51dbe30 8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff changeset
     1
/*
7799a51dbe30 8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff changeset
     2
 * @test /nodynamiccopyright/
7799a51dbe30 8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff changeset
     3
 * @bug 8231827
7799a51dbe30 8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff changeset
     4
 * @summary Basic pattern bindings scope test
7799a51dbe30 8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff changeset
     5
 * @compile/fail/ref=DuplicateBindingTest.out -XDrawDiagnostics --enable-preview -source ${jdk.version} DuplicateBindingTest.java
7799a51dbe30 8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff changeset
     6
 */
7799a51dbe30 8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff changeset
     7
7799a51dbe30 8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff changeset
     8
public class DuplicateBindingTest {
7799a51dbe30 8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff changeset
     9
7799a51dbe30 8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff changeset
    10
    int f;
7799a51dbe30 8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff changeset
    11
7799a51dbe30 8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff changeset
    12
    public static void main(String[] args) {
7799a51dbe30 8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff changeset
    13
7799a51dbe30 8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff changeset
    14
        if (args != null) {
7799a51dbe30 8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff changeset
    15
            int s;
7799a51dbe30 8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff changeset
    16
            if (args[0] instanceof String s) { // NOT OK. Redef same scope.
7799a51dbe30 8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff changeset
    17
            }
7799a51dbe30 8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff changeset
    18
            if (args[0] instanceof String f) { // OK to redef field.
7799a51dbe30 8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff changeset
    19
            }
7799a51dbe30 8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff changeset
    20
        }
7799a51dbe30 8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff changeset
    21
    }
7799a51dbe30 8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents:
diff changeset
    22
}