changes.
[IRC.git] / Robust / JavaGrammar / tests / Eric.java
1 /** Some valid java code from Eric Blake.  Some of these constructions
2  *  broke previous versions of the grammars.  These should all compile
3  *  with any JLS2 javac, as well as parse correctly (no syntax errors)
4  *  using the java12.cup/java14.cup/java15.cup grammars in this package. */
5 class Eric {
6     // parenthesized variables on the left-hand-size of assignments
7     // are legal according to JLS 2.  See comments on jikes bug 105
8     //         http://www-124.ibm.com/developerworks/bugs/?func=detailbug&bug_id=105&group_id=10
9     // for more details. According to Eric Blake:
10     //       The 2nd edition JLS is weak on this point - the grammar
11     //       in 15.26 prohibits assignments to parenthesized
12     //       variables, but earlier in 15.8.5 it states that a
13     //       parenthesized variable is still a variable (in JLS1, a
14     //       parenthesized variable was a value), and the intent of
15     //       assignment is that a variable appear on the left hand
16     //       side.  Also, the grammar in chapter 18 (if you can call
17     //       it such, because of its numerous typos and ambiguities)
18     //       permits assignment to parenthesized variables.
19     void m(int i) {
20         (i) = 1;
21     }
22     // array access of an initialized array creation is legal; see Sun
23     // bugs 4091602, 4321177:
24     //   http://developer.java.sun.com/developer/bugParade/bugs/4091602.html
25     //   http://developer.java.sun.com/developer/bugParade/bugs/4321177.html
26     // Eric Blake says:
27     //   Again, the body of the JLS prohibits this, but chapter 18 permits it.
28     int i = new int[]{0}[0];
29     int j = new char[] { 'O', 'K' }.length;
30
31     // plain identifiers can qualify instance creation and explicit
32     // constructors; see Sun bug 4750181:
33     //   http://developer.java.sun.com/developer/bugParade/bugs/4750181.html
34     // Eric Blake says:
35     //   Sun admits the grammars between the earlier chapters and
36     //   chapter 18 are incompatible, so they are not sure whether
37     //   things like "identifier.new name()" should be legal or
38     //   not. Chapter 18 treats identifiers as primaries, and javac
39     //   compiles them.
40     class B { };
41     B b;
42     void foo(Eric e) {
43         e.b = e.new B();
44     }
45 }