Bug 28617 - Qualified super reference cannot be surrounded with parentheses.
Summary: Qualified super reference cannot be surrounded with parentheses.
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.1   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 2.1 M5   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-12-18 10:25 EST by Olivier Thomann CLA
Modified: 2003-02-07 11:45 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Olivier Thomann CLA 2002-12-18 10:25:36 EST
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.
Comment 1 Philipe Mulet CLA 2002-12-19 06:16:59 EST
Ok by me.
Comment 2 Philipe Mulet CLA 2002-12-20 05:07:16 EST
In a similar fashion we should reject (++i)++;
Comment 3 Olivier Thomann CLA 2003-01-06 10:52:48 EST
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)
Comment 4 Olivier Thomann CLA 2003-01-06 11:53:10 EST
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.
Comment 5 Philipe Mulet CLA 2003-01-08 07:33:06 EST
I would make it sound a little more generic:

IProblem.InvalidParenthesizedExpression

ProblemReporter.illegalParenthesizedExpression(...)
Comment 6 Olivier Thomann CLA 2003-01-08 08:36:30 EST
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.
Comment 7 David Audel CLA 2003-02-07 11:45:26 EST
Verified.