langtools/test/tools/javac/ParseConditional.java
author jlahoda
Tue, 16 Aug 2016 16:43:00 +0200
changeset 40504 0a01f6710c84
parent 26662 7cf828d7c8fc
permissions -rw-r--r--
8078561: Error message should be generated once when -source 6 is specified Summary: Code to avoid duplicated errors about features not supported in the current source level moved to Log Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
26662
7cf828d7c8fc 8055080: Group 9d: golden files for tests in tools/javac dir
sogoel
parents: 5520
diff changeset
     2
 * @test /nodynamiccopyright/
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * @bug 4092958
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 * @summary The compiler was too permissive in its parsing of conditional
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 *          expressions.
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * @author turnidge
06bc494ca11e Initial load
duke
parents:
diff changeset
     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
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
public class ParseConditional {
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
    public static void main(String[] args) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
        boolean condition = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
        int a = 1;
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
        int b = 2;
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
        int c = 3;
06bc494ca11e Initial load
duke
parents:
diff changeset
    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
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
}