Bug 44538 - Strange compile error
Summary: Strange compile error
Status: RESOLVED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.0 M4   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-10-09 08:37 EDT by Dirk Baeumer CLA
Modified: 2003-10-09 09:57 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 Dirk Baeumer CLA 2003-10-09 08:37:13 EDT
I20031008

Don't know if this is a bug or if I don't understand the meaning of the 
compile error. Compile the following class

public class A {
	public void bar() {
		class C extends A {
			public void foo() {
				
			}
		}
		A a= new A() {
			public void foo() {
				
			}
		};
		class D extends C {
			
		};
	}
}
Comment 1 Philipe Mulet CLA 2003-10-09 09:52:01 EDT
----------
1. ERROR in d:\eclipse\workspaces\dev3.0\plugins\Crap\src\A.java (at line 13)
	class D extends C {
	      ^
No enclosing instance of type A is available due to some intermediate 
constructor invocation
----------

The error is valid though a little cryptic. Jikes would say:
 The innermost enclosing instance of type "A" is "this", which is not yet 
initialized here.

javac 1.4.2 incorrectly accepts this code.
Comment 2 Philipe Mulet CLA 2003-10-09 09:57:07 EDT
Problem is that constructor for D is trying to invoke super constructor from C, 
which requires an enclosing instance of type A.

However, since D extends C extends A, it appears that 'this' (D) is the best 
candidate for such an enclosing instance. However, it is forbidden, since you 
are still in a constructor invocation (cannot use 'this').

Correct code should be:
class D extends C {
  D() { A.this.super(); }

also see bug 42588