1 /*
2  * @test /nodynamiccopyright/
3  * @bug 4092958
4  * @summary The compiler was too permissive in its parsing of conditional
5  *          expressions.
6  * @author turnidge
7  *
8  * @compile/fail/ref=ParseConditional.out -XDrawDiagnostics ParseConditional.java
9  */
10 
11 public class ParseConditional {
main(String[] args)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;
18         // The following line should give an error because the conditional ?: operator
19         // is higher priority than the final assignment operator, between c and d.
20         // As such, the correct parsing is:
21         //   a = (condition ? b = c : c) = d;
22         // and it is illegal to try and assign to the value of the conditional expression.
23         a = condition ? b = c : c = d;
24     }
25 }
26