author | mcimadamore |
Wed, 26 Oct 2016 15:41:25 +0100 | |
changeset 41856 | 13a056e8f16e |
parent 26662 | 7cf828d7c8fc |
permissions | -rw-r--r-- |
10 | 1 |
/* |
26662
7cf828d7c8fc
8055080: Group 9d: golden files for tests in tools/javac dir
sogoel
parents:
5520
diff
changeset
|
2 |
* @test /nodynamiccopyright/ |
10 | 3 |
* @bug 4092958 |
4 |
* @summary The compiler was too permissive in its parsing of conditional |
|
5 |
* expressions. |
|
6 |
* @author turnidge |
|
7 |
* |
|
26662
7cf828d7c8fc
8055080: Group 9d: golden files for tests in tools/javac dir
sogoel
parents:
5520
diff
changeset
|
8 |
* @compile/fail/ref=ParseConditional.out -XDrawDiagnostics ParseConditional.java |
10 | 9 |
*/ |
10 |
||
11 |
public class ParseConditional { |
|
12 |
public static void main(String[] args) { |
|
13 |
boolean condition = true; |
|
14 |
int a = 1; |
|
15 |
int b = 2; |
|
16 |
int c = 3; |
|
17 |
int d = 4; |
|
26662
7cf828d7c8fc
8055080: Group 9d: golden files for tests in tools/javac dir
sogoel
parents:
5520
diff
changeset
|
18 |
// The following line should give an error because the conditional ?: operator |
7cf828d7c8fc
8055080: Group 9d: golden files for tests in tools/javac dir
sogoel
parents:
5520
diff
changeset
|
19 |
// is higher priority than the final assignment operator, between c and d. |
7cf828d7c8fc
8055080: Group 9d: golden files for tests in tools/javac dir
sogoel
parents:
5520
diff
changeset
|
20 |
// As such, the correct parsing is: |
7cf828d7c8fc
8055080: Group 9d: golden files for tests in tools/javac dir
sogoel
parents:
5520
diff
changeset
|
21 |
// a = (condition ? b = c : c) = d; |
7cf828d7c8fc
8055080: Group 9d: golden files for tests in tools/javac dir
sogoel
parents:
5520
diff
changeset
|
22 |
// and it is illegal to try and assign to the value of the conditional expression. |
7cf828d7c8fc
8055080: Group 9d: golden files for tests in tools/javac dir
sogoel
parents:
5520
diff
changeset
|
23 |
a = condition ? b = c : c = d; |
10 | 24 |
} |
25 |
} |