Bug 44538

Summary: Strange compile error
Product: [Eclipse Project] JDT Reporter: Dirk Baeumer <dirk_baeumer>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: RESOLVED WORKSFORME QA Contact:
Severity: normal    
Priority: P3    
Version: 3.0   
Target Milestone: 3.0 M4   
Hardware: PC   
OS: Windows XP   
Whiteboard:

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