1 /*
2 * @test /nodynamiccopyright/
3 * @bug 8206986
4 * @summary Verify the type of a conditional expression with nested switch expression is computed properly
5 * @compile/fail/ref=BooleanNumericNonNumeric.out -XDrawDiagnostics --enable-preview -source 12 BooleanNumericNonNumeric.java
6 */
7
8 public class BooleanNumericNonNumeric {
9
10 private void test(boolean b, int i) {
11 int r1 = 1 + (b ? switch (i) { //boolean, error
12 default -> true;
13 } : false);
14 int r2 = 1 + (b ? switch (i) { //int, ok
15 default -> 0;
16 } : 1);
17 (b ? switch (i) { //int, error
18 default -> 0;
19 } : 1).toString();
20 (b ? switch (i) { //"object", ok
21 case 0 -> true;
22 default -> 0;
23 } : 1).toString();
24 }
25
|
1 /*
2 * @test /nodynamiccopyright/
3 * @bug 8206986
4 * @summary Verify the type of a conditional expression with nested switch expression is computed properly
5 * @compile/fail/ref=BooleanNumericNonNumeric.out -XDrawDiagnostics --enable-preview -source 13 BooleanNumericNonNumeric.java
6 */
7
8 public class BooleanNumericNonNumeric {
9
10 private void test(boolean b, int i) {
11 int r1 = 1 + (b ? switch (i) { //boolean, error
12 default -> true;
13 } : false);
14 int r2 = 1 + (b ? switch (i) { //int, ok
15 default -> 0;
16 } : 1);
17 (b ? switch (i) { //int, error
18 default -> 0;
19 } : 1).toString();
20 (b ? switch (i) { //"object", ok
21 case 0 -> true;
22 default -> 0;
23 } : 1).toString();
24 }
25
|