Bug 5940 - Instance initializer in anon inner class generates errors
Summary: Instance initializer in anon inner class generates errors
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows 98
: P3 normal (vote)
Target Milestone: 2.0 M1   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2001-11-14 21:01 EST by Chris Smith CLA
Modified: 2002-01-11 09:22 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Smith CLA 2001-11-14 21:01:35 EST
Compiling the following code:

public class Test
{
	Object t;

	private void testMethod()
	{
		t = new Object() {
			{
			}
		};
	}
}

Under the Eclipse environment produces this error:

The operator unknown operator is undefined for the argument type(s) 
java.lang.Object, <anonymous subclass of java.lang.Object>

By my interpretation of the JLS, this should be legal.  The Sun javac compiler 
compiles it without problems in versions 1.1.8, 1.3, and 1.4 beta 3.  
Incidentally, changing t, in the example above, to be a local variable removes 
the error and allows the code to compile successfully.
Comment 1 Philipe Mulet CLA 2001-11-15 08:33:51 EST
This is actually a bug in our Parser, reducing incorrectly the assignment to 
the anonymous type instance.

The bug disappears if removing the initializer nested inside. After analysis, 
it appears that the int stack of the parser is left inconsistent after the 
initializer got consumed, and the initializer start position is left on it.

However, the assignment operator code is supposed to be on top of the stack 
when reducing the assignment, leading to an unknown operator error afterwards.