Bug 91114 - [jdt-parser] Parser error on System.out.printf("..." + (after-before) + "...")
Summary: [jdt-parser] Parser error on System.out.printf("..." + (after-before) + "...")
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.5.0M2   Edit
Hardware: Sun All
: P3 normal (vote)
Target Milestone: 1.5.0 M3   Edit
Assignee: Adrian Colyer CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-04-12 08:03 EDT by Simon Heinzle CLA
Modified: 2005-08-19 09:51 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Heinzle CLA 2005-04-12 08:03:15 EDT
Following code fragment:

*****************************
class Foo {
        public void bar () {
                long before = 0;
                long after = 0;
                System.out.println("... " + (before - after) + " ...");

        }
}
*****************************

leads to following parser error

*****************************
[...].java:25 [error] Syntax error on token "-", invalid AssignmentOperator
System.out.println("... " + (before - after) + " ...");
*****************************

Problems seems to vanish when I rename the before variable.
Comment 1 Simon Heinzle CLA 2005-04-12 08:09:28 EDT
Same applies if
    System.out.println("... " + (after - before) + " ...");

again, renaming after solves the problem
Comment 2 Andrew Clement CLA 2005-04-12 08:12:19 EDT
whilst Adrian has the parser open, he can take a look :)
Comment 3 Michael Finney CLA 2005-05-22 16:32:05 EDT
Verified as happening on Windows 2000, PC hardware. I would switch the hardware 
to All if I had the power. Recommend that this never gets assigned as minor 
since some legacy/existing code cannot be changed to workaround this bug.
Comment 4 Adrian Colyer CLA 2005-05-23 03:50:16 EDT
The problem is in the way that AspectJ handles its pseudo-keywords. Identifiers
such as "aspect", "pointcut", "before", "after" etc. are treated as keywords in
the context in which they may legitimately appear, but as identifiers in other
contexts. This *should* allow you to name your variable before and after in the
fragments of code shown in this bug report, but where the grammar has been
extended to cope with the new features of Java5, we clearly haven't yet nailed
all of the places where we need to be accomodating. 

Fix will be to find the grammar production for these expressions and ensure that
any use of 'Identifier' is replaced by 'JavaIdentifier'. Still targetting to fix
this as part of the current milestone (M3) development.
Comment 5 Adrian Colyer CLA 2005-08-19 09:51:00 EDT
turns out a whole family of expressions fail, eg.

before * after, before >>>  x, after \ before etc..

all of these are now successfully compiled as expected.

Fix committed to tree.