2007-12-01 00:00:00 +00:00
|
|
|
/*
|
2014-09-13 00:05:18 +00:00
|
|
|
* @test /nodynamiccopyright/
|
2007-12-01 00:00:00 +00:00
|
|
|
* @bug 4092958
|
|
|
|
* @summary The compiler was too permissive in its parsing of conditional
|
|
|
|
* expressions.
|
|
|
|
* @author turnidge
|
|
|
|
*
|
2014-09-13 00:05:18 +00:00
|
|
|
* @compile/fail/ref=ParseConditional.out -XDrawDiagnostics ParseConditional.java
|
2007-12-01 00:00:00 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
public class ParseConditional {
|
2023-01-17 04:43:40 +00:00
|
|
|
public static void meth() {
|
2007-12-01 00:00:00 +00:00
|
|
|
boolean condition = true;
|
|
|
|
int a = 1;
|
|
|
|
int b = 2;
|
|
|
|
int c = 3;
|
|
|
|
int d = 4;
|
2014-09-13 00:05:18 +00:00
|
|
|
// The following line should give an error because the conditional ?: operator
|
|
|
|
// is higher priority than the final assignment operator, between c and d.
|
|
|
|
// As such, the correct parsing is:
|
|
|
|
// a = (condition ? b = c : c) = d;
|
|
|
|
// and it is illegal to try and assign to the value of the conditional expression.
|
|
|
|
a = condition ? b = c : c = d;
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|