author | jlahoda |
Wed, 21 Nov 2018 15:22:57 +0100 | |
changeset 52635 | 6938c8ef179a |
parent 51563 | de411d537aae |
child 53023 | 6879069d9d94 |
permissions | -rw-r--r-- |
51563
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
1 |
/* |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
2 |
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
4 |
* |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
8 |
* |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
13 |
* accompanied this code). |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
14 |
* |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
18 |
* |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
21 |
* questions. |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
22 |
*/ |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
23 |
|
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
24 |
import java.io.IOException; |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
25 |
import java.util.List; |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
26 |
|
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
27 |
import org.testng.ITestResult; |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
28 |
import org.testng.annotations.AfterMethod; |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
29 |
import org.testng.annotations.Test; |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
30 |
import tools.javac.combo.JavacTemplateTestBase; |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
31 |
|
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
32 |
import static java.util.stream.Collectors.toList; |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
33 |
|
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
34 |
@Test |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
35 |
public class ExpSwitchNestingTest extends JavacTemplateTestBase { |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
36 |
private static final String RUNNABLE = "Runnable r = () -> { # };"; |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
37 |
private static final String INT_FN = "java.util.function.IntSupplier r = () -> { # };"; |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
38 |
private static final String LABEL = "label: #"; |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
39 |
private static final String DEF_LABEL_VAR = "int label = 0; { # }"; |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
40 |
private static final String FOR = "for (int i=0; i<10; i++) { # }"; |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
41 |
private static final String FOR_EACH = "for (int i : new int[] {}) { # }"; |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
42 |
private static final String WHILE = "while (cond) { # }"; |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
43 |
private static final String DO = "do { # } while (cond);"; |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
44 |
private static final String SSWITCH = "switch (x) { case 0: # };"; |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
45 |
private static final String ESWITCH_Z = "int res = switch (x) { case 0 -> { # } default -> 0; };"; |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
46 |
private static final String ESWITCH_S = "String res_string = switch (x) { case 0 -> { # } default -> \"default\"; };"; |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
47 |
private static final String INT_FN_ESWITCH = "java.util.function.IntSupplier r = switch (x) { case 0 -> { # } default -> null; };"; |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
48 |
private static final String INT_ESWITCH_DEFAULT = "int res = switch (x) { default -> { # } };"; |
52635
6938c8ef179a
8212982: Rule cases in switch expression accepted even if complete normally
jlahoda
parents:
51563
diff
changeset
|
49 |
private static final String IF = "if (cond) { # } else throw new RuntimeException();"; |
51563
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
50 |
private static final String BLOCK = "{ # }"; |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
51 |
private static final String BREAK_Z = "break 0;"; |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
52 |
private static final String BREAK_S = "break \"hello world\";"; |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
53 |
private static final String BREAK_INT_FN = "break () -> 0 ;"; |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
54 |
private static final String BREAK_N = "break;"; |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
55 |
private static final String BREAK_L = "break label;"; |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
56 |
private static final String RETURN_Z = "return 0;"; |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
57 |
private static final String RETURN_N = "return;"; |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
58 |
private static final String RETURN_S = "return \"Hello\";"; |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
59 |
private static final String CONTINUE_N = "continue;"; |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
60 |
private static final String CONTINUE_L = "continue label;"; |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
61 |
private static final String NOTHING = "System.out.println();"; |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
62 |
|
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
63 |
// containers that do not require exhaustiveness |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
64 |
private static final List<String> CONTAINERS |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
65 |
= List.of(RUNNABLE, FOR, WHILE, DO, SSWITCH, IF, BLOCK); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
66 |
// containers that do not require exhaustiveness that are statements |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
67 |
private static final List<String> CONTAINER_STATEMENTS |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
68 |
= List.of(FOR, WHILE, DO, SSWITCH, IF, BLOCK); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
69 |
|
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
70 |
@AfterMethod |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
71 |
public void dumpTemplateIfError(ITestResult result) { |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
72 |
// Make sure offending template ends up in log file on failure |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
73 |
if (!result.isSuccess()) { |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
74 |
System.err.printf("Diagnostics: %s%nTemplate: %s%n", diags.errorKeys(), sourceFiles.stream().map(p -> p.snd).collect(toList())); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
75 |
} |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
76 |
} |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
77 |
|
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
78 |
private void program(String... constructs) { |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
79 |
String s = "class C { static boolean cond = false; static int x = 0; void m() { # } }"; |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
80 |
for (String c : constructs) |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
81 |
s = s.replace("#", c); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
82 |
addSourceFile("C.java", new StringTemplate(s)); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
83 |
} |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
84 |
|
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
85 |
private void assertOK(String... constructs) { |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
86 |
reset(); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
87 |
addCompileOptions("--enable-preview", "-source", "12"); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
88 |
program(constructs); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
89 |
try { |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
90 |
compile(); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
91 |
} |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
92 |
catch (IOException e) { |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
93 |
throw new RuntimeException(e); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
94 |
} |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
95 |
assertCompileSucceeded(); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
96 |
} |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
97 |
|
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
98 |
private void assertOKWithWarning(String warning, String... constructs) { |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
99 |
reset(); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
100 |
addCompileOptions("--enable-preview", "-source", "12"); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
101 |
program(constructs); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
102 |
try { |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
103 |
compile(); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
104 |
} |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
105 |
catch (IOException e) { |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
106 |
throw new RuntimeException(e); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
107 |
} |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
108 |
assertCompileSucceededWithWarning(warning); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
109 |
} |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
110 |
|
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
111 |
private void assertFail(String expectedDiag, String... constructs) { |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
112 |
reset(); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
113 |
addCompileOptions("--enable-preview", "-source", "12"); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
114 |
program(constructs); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
115 |
try { |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
116 |
compile(); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
117 |
} |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
118 |
catch (IOException e) { |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
119 |
throw new RuntimeException(e); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
120 |
} |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
121 |
assertCompileFailed(expectedDiag); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
122 |
} |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
123 |
|
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
124 |
public void testReallySimpleCases() { |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
125 |
for (String s : CONTAINERS) |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
126 |
assertOK(s, NOTHING); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
127 |
for (String s : CONTAINER_STATEMENTS) |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
128 |
assertOK(LABEL, s, NOTHING); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
129 |
} |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
130 |
|
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
131 |
public void testLambda() { |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
132 |
assertOK(RUNNABLE, RETURN_N); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
133 |
assertOK(RUNNABLE, NOTHING); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
134 |
assertOK(INT_FN, RETURN_Z); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
135 |
assertFail("compiler.err.break.outside.switch.loop", RUNNABLE, BREAK_N); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
136 |
assertFail("compiler.err.break.complex.value.no.switch.expression", RUNNABLE, BREAK_Z); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
137 |
assertFail("compiler.err.break.complex.value.no.switch.expression", RUNNABLE, BREAK_S); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
138 |
assertFail("compiler.err.break.outside.switch.loop", INT_FN, BREAK_N); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
139 |
assertFail("compiler.err.break.complex.value.no.switch.expression", INT_FN, BREAK_Z); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
140 |
assertFail("compiler.err.break.complex.value.no.switch.expression", INT_FN, BREAK_S); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
141 |
assertFail("compiler.err.cont.outside.loop", RUNNABLE, CONTINUE_N); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
142 |
assertFail("compiler.err.undef.label", RUNNABLE, BREAK_L); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
143 |
assertFail("compiler.err.undef.label", RUNNABLE, CONTINUE_L); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
144 |
assertFail("compiler.err.cont.outside.loop", INT_FN, CONTINUE_N); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
145 |
assertFail("compiler.err.undef.label", INT_FN, BREAK_L); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
146 |
assertFail("compiler.err.undef.label", INT_FN, CONTINUE_L); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
147 |
assertFail("compiler.err.undef.label", LABEL, BLOCK, RUNNABLE, BREAK_L); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
148 |
assertFail("compiler.err.undef.label", LABEL, BLOCK, RUNNABLE, CONTINUE_L); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
149 |
assertFail("compiler.err.undef.label", LABEL, BLOCK, INT_FN, BREAK_L); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
150 |
assertFail("compiler.err.undef.label", LABEL, BLOCK, INT_FN, CONTINUE_L); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
151 |
} |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
152 |
|
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
153 |
public void testEswitch() { |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
154 |
//Int-valued switch expressions |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
155 |
assertOK(ESWITCH_Z, BREAK_Z); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
156 |
assertOK(LABEL, BLOCK, ESWITCH_Z, BREAK_Z); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
157 |
assertFail("compiler.err.break.missing.value", ESWITCH_Z, BREAK_N); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
158 |
assertFail("compiler.err.prob.found.req", ESWITCH_Z, BREAK_S); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
159 |
assertFail("compiler.err.cant.resolve.location", ESWITCH_Z, BREAK_L); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
160 |
assertFail("compiler.err.break.outside.switch.expression", LABEL, BLOCK, ESWITCH_Z, BREAK_L); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
161 |
assertFail("compiler.err.undef.label", ESWITCH_Z, CONTINUE_L); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
162 |
assertFail("compiler.err.cont.outside.loop", ESWITCH_Z, CONTINUE_N); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
163 |
assertFail("compiler.err.return.outside.switch.expression", ESWITCH_Z, RETURN_N); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
164 |
assertFail("compiler.err.return.outside.switch.expression", ESWITCH_Z, RETURN_Z); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
165 |
|
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
166 |
assertOK(INT_ESWITCH_DEFAULT, BREAK_Z); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
167 |
assertFail("compiler.err.break.missing.value", INT_ESWITCH_DEFAULT, BREAK_N); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
168 |
assertFail("compiler.err.prob.found.req", INT_ESWITCH_DEFAULT, BREAK_S); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
169 |
assertFail("compiler.err.cant.resolve.location", INT_ESWITCH_DEFAULT, BREAK_L); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
170 |
|
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
171 |
|
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
172 |
// String-valued switch expressions |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
173 |
assertOK(ESWITCH_S, BREAK_S); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
174 |
assertOK(LABEL, BLOCK, ESWITCH_S, BREAK_S); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
175 |
assertFail("compiler.err.break.missing.value", ESWITCH_S, BREAK_N); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
176 |
assertFail("compiler.err.prob.found.req", ESWITCH_S, BREAK_Z); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
177 |
assertFail("compiler.err.cant.resolve.location", ESWITCH_S, BREAK_L); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
178 |
assertFail("compiler.err.break.outside.switch.expression", LABEL, BLOCK, ESWITCH_S, BREAK_L); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
179 |
assertFail("compiler.err.undef.label", ESWITCH_S, CONTINUE_L); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
180 |
assertFail("compiler.err.cont.outside.loop", ESWITCH_S, CONTINUE_N); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
181 |
assertFail("compiler.err.return.outside.switch.expression", ESWITCH_S, RETURN_N); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
182 |
assertFail("compiler.err.return.outside.switch.expression", ESWITCH_S, RETURN_S); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
183 |
// Function-valued switch expression |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
184 |
assertOK(INT_FN_ESWITCH, BREAK_INT_FN); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
185 |
assertFail("compiler.err.break.missing.value", INT_FN_ESWITCH, BREAK_N); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
186 |
assertFail("compiler.err.prob.found.req", INT_FN_ESWITCH, BREAK_Z); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
187 |
assertFail("compiler.err.prob.found.req", INT_FN_ESWITCH, BREAK_S); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
188 |
|
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
189 |
assertFail("compiler.err.cant.resolve.location", INT_FN_ESWITCH, BREAK_L); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
190 |
assertFail("compiler.err.break.outside.switch.expression", LABEL, BLOCK, INT_FN_ESWITCH, BREAK_L); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
191 |
assertFail("compiler.err.undef.label", INT_FN_ESWITCH, CONTINUE_L); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
192 |
assertFail("compiler.err.cont.outside.loop", INT_FN_ESWITCH, CONTINUE_N); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
193 |
assertFail("compiler.err.return.outside.switch.expression", INT_FN_ESWITCH, RETURN_N); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
194 |
assertFail("compiler.err.return.outside.switch.expression", INT_FN_ESWITCH, RETURN_S); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
195 |
|
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
196 |
} |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
197 |
|
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
198 |
public void testNestedInExpSwitch() { |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
199 |
assertOK(ESWITCH_Z, IF, BREAK_Z); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
200 |
assertOK(ESWITCH_Z, BLOCK, BREAK_Z); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
201 |
// |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
202 |
assertOK(ESWITCH_Z, IF, IF, BREAK_Z); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
203 |
assertOK(ESWITCH_Z, IF, BLOCK, BREAK_Z); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
204 |
assertOK(ESWITCH_Z, BLOCK, IF, BREAK_Z); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
205 |
assertOK(ESWITCH_Z, BLOCK, BLOCK, BREAK_Z); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
206 |
// |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
207 |
assertOK(ESWITCH_Z, IF, IF, IF, BREAK_Z); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
208 |
assertOK(ESWITCH_Z, IF, IF, BLOCK, BREAK_Z); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
209 |
assertOK(ESWITCH_Z, IF, BLOCK, IF, BREAK_Z); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
210 |
assertOK(ESWITCH_Z, IF, BLOCK, BLOCK, BREAK_Z); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
211 |
assertOK(ESWITCH_Z, BLOCK, IF, IF, BREAK_Z); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
212 |
assertOK(ESWITCH_Z, BLOCK, IF, BLOCK, BREAK_Z); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
213 |
assertOK(ESWITCH_Z, BLOCK, BLOCK, IF, BREAK_Z); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
214 |
assertOK(ESWITCH_Z, BLOCK, BLOCK, BLOCK, BREAK_Z); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
215 |
// |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
216 |
assertFail("compiler.err.break.expr.not.immediate", ESWITCH_Z, SSWITCH, BREAK_Z); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
217 |
assertFail("compiler.err.break.expr.not.immediate", ESWITCH_Z, FOR, BREAK_Z); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
218 |
assertFail("compiler.err.break.expr.not.immediate", ESWITCH_Z, WHILE, BREAK_Z); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
219 |
assertFail("compiler.err.break.expr.not.immediate", ESWITCH_Z, DO, BREAK_Z); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
220 |
assertFail("compiler.err.break.complex.value.no.switch.expression", ESWITCH_Z, INT_FN, BREAK_Z); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
221 |
assertFail("compiler.err.break.expr.not.immediate", ESWITCH_Z, SSWITCH, IF, BREAK_Z); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
222 |
assertFail("compiler.err.break.expr.not.immediate", ESWITCH_Z, FOR, IF, BREAK_Z); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
223 |
assertFail("compiler.err.break.expr.not.immediate", ESWITCH_Z, WHILE, IF, BREAK_Z); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
224 |
assertFail("compiler.err.break.expr.not.immediate", ESWITCH_Z, DO, IF, BREAK_Z); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
225 |
assertFail("compiler.err.break.expr.not.immediate", ESWITCH_Z, BLOCK, SSWITCH, IF, BREAK_Z); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
226 |
assertFail("compiler.err.break.expr.not.immediate", ESWITCH_Z, BLOCK, FOR, IF, BREAK_Z); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
227 |
assertFail("compiler.err.break.expr.not.immediate", ESWITCH_Z, BLOCK, WHILE, IF, BREAK_Z); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
228 |
assertFail("compiler.err.break.expr.not.immediate", ESWITCH_Z, BLOCK, DO, IF, BREAK_Z); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
229 |
} |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
230 |
|
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
231 |
public void testBreakExpressionLabelDisambiguation() { |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
232 |
assertOK(DEF_LABEL_VAR, ESWITCH_Z, BREAK_L); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
233 |
assertFail("compiler.err.break.ambiguous.target", LABEL, FOR, BLOCK, DEF_LABEL_VAR, ESWITCH_Z, BREAK_L); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
234 |
assertFail("compiler.err.break.ambiguous.target", DEF_LABEL_VAR, ESWITCH_Z, LABEL, FOR, BREAK_L); //label break |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
235 |
assertFail("compiler.err.break.ambiguous.target", DEF_LABEL_VAR, LABEL, BLOCK, ESWITCH_Z, BREAK_L); //expression break |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
236 |
// |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
237 |
} |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
238 |
|
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
239 |
public void testFunReturningSwitchExp() { |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
240 |
assertOK(INT_FN_ESWITCH, BREAK_INT_FN); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
241 |
} |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
242 |
|
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
243 |
public void testContinueLoops() { |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
244 |
assertOK(LABEL, FOR, CONTINUE_L); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
245 |
assertOK(LABEL, FOR_EACH, CONTINUE_L); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
246 |
assertOK(LABEL, WHILE, CONTINUE_L); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
247 |
assertOK(LABEL, DO, CONTINUE_L); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
248 |
assertFail("compiler.err.not.loop.label", LABEL, CONTINUE_L); |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
249 |
} |
de411d537aae
8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents:
diff
changeset
|
250 |
} |