Community
Participate
Working Groups
Using 1217, we don't reject the following code: class A { class B { public String toString() { return (A.super).toString(); } } } javac and jikes rejects it. If you remove the parentheses around A.super, then it compiles fine with javac and jikes. NOTE: replacing 'super' with 'this' is good enough to compile the code fine. The fix is trivial. We simply need to check if the parentheses bits is set for a qualified super reference or we should not consume Name.super as a primary expression. See http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#23302 I would go for the check on the parentheses bits instead of a change in the grammar, because this allows us to consider this problem different from a compile error.
Ok by me.
In a similar fashion we should reject (++i)++;
We already reject such a code with: ---------- 1. ERROR in D:\temp\A.java (at line 5) (++i)++; ^^^^^ Invalid argument to operation ++/-- ---------- 1 problem (1 error)
I'd like to add: 1) In IProblem: int CannotBeSurroundedByParentheses = Syntax + Internal + 225; 2) QualifiedSuperReference::resolveType method: if ((this.bits & ParenthesizedMASK) != 0) { scope.problemReporter().qualifiedSuperReferenceCannotBeSurroundedByParentheses(this); return null; } 3) In problem/messages.properties: 225 = A qualified super reference cannot be surrounded by parentheses 4) In ProblemReporter: public void qualifiedSuperReferenceCannotBeSurroundedByParentheses(AstNode reference) { this.handle( IProblem.CannotBeSurroundedByParentheses, NoArgument, NoArgument, reference.sourceStart, reference.sourceEnd); } Then I get the following error for this bug's test case: ---------- 1. ERROR in D:\temp\A.java (at line 4) return (A.super).toString(); ^^^^^^^^^ A qualified super reference cannot be surrounded by parentheses ---------- 1 problem (1 error) Let me know if the naming is good enough. I don't want to release this without checking first since IProblem is an API interface.
I would make it sound a little more generic: IProblem.InvalidParenthesizedExpression ProblemReporter.illegalParenthesizedExpression(...)
Now we have: ---------- 1. ERROR in D:\temp\A.java (at line 4) return (A.super).toString(); ^^^^^^^^^ Invalid parenthesized expression ---------- 1 problem (1 error) Fixed and released in 2.1 stream. Regression test added.
Verified.