langtools/test/tools/javac/ParseConditional.java
author sogoel
Fri, 12 Sep 2014 17:05:18 -0700
changeset 26662 7cf828d7c8fc
parent 5520 86e4b9a9da40
permissions -rw-r--r--
8055080: Group 9d: golden files for tests in tools/javac dir Reviewed-by: jjg, mcimadamore, jlahoda

/*
 * @test /nodynamiccopyright/
 * @bug 4092958
 * @summary The compiler was too permissive in its parsing of conditional
 *          expressions.
 * @author turnidge
 *
 * @compile/fail/ref=ParseConditional.out -XDrawDiagnostics ParseConditional.java
 */

public class ParseConditional {
    public static void main(String[] args) {
        boolean condition = true;
        int a = 1;
        int b = 2;
        int c = 3;
        int d = 4;
        // 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;
    }
}