55306
|
1 |
/**
|
|
2 |
* @test /nodynamiccopyright/
|
|
3 |
* @summary Verify that definite assignment works (illegal code)
|
59021
|
4 |
* @compile/fail/ref=DefiniteAssignment2.out -XDrawDiagnostics DefiniteAssignment2.java
|
55306
|
5 |
*/
|
|
6 |
public class DefiniteAssignment2 {
|
|
7 |
|
|
8 |
public static void main(String[] args) {
|
|
9 |
int a = 0;
|
|
10 |
E e = E.A;
|
|
11 |
|
|
12 |
{
|
|
13 |
int x;
|
|
14 |
|
|
15 |
switch(a) {
|
|
16 |
case 0: break;
|
|
17 |
default: x = 1; break;
|
|
18 |
}
|
|
19 |
|
|
20 |
System.err.println(x);
|
|
21 |
}
|
|
22 |
|
|
23 |
{
|
|
24 |
int x;
|
|
25 |
|
|
26 |
switch(a) {
|
|
27 |
case 0 -> {}
|
|
28 |
default -> x = 1;
|
|
29 |
}
|
|
30 |
|
|
31 |
System.err.println(x);
|
|
32 |
}
|
|
33 |
|
|
34 |
{
|
|
35 |
int x;
|
|
36 |
|
|
37 |
switch(a) {
|
|
38 |
case 0: x = 0; break;
|
|
39 |
default:
|
|
40 |
}
|
|
41 |
|
|
42 |
System.err.println(x);
|
|
43 |
}
|
|
44 |
|
|
45 |
{
|
|
46 |
int x;
|
|
47 |
|
|
48 |
switch(e) {
|
|
49 |
case A, B, C -> x = 0;
|
|
50 |
}
|
|
51 |
|
|
52 |
System.err.println(x);
|
|
53 |
}
|
|
54 |
|
|
55 |
{
|
|
56 |
int x;
|
|
57 |
|
|
58 |
switch(e) {
|
|
59 |
case A, B, C -> { x = 0; }
|
|
60 |
}
|
|
61 |
|
|
62 |
System.err.println(x);
|
|
63 |
}
|
|
64 |
|
|
65 |
{
|
|
66 |
int x;
|
|
67 |
|
|
68 |
switch(e) {
|
|
69 |
case A, B -> { x = 0; }
|
|
70 |
case C -> throw new IllegalStateException();
|
|
71 |
}
|
|
72 |
|
|
73 |
System.err.println(x);
|
|
74 |
}
|
|
75 |
}
|
|
76 |
|
|
77 |
enum E {
|
|
78 |
A, B, C;
|
|
79 |
}
|
|
80 |
}
|