Bug 60442 - Invalid "no enclosing type" error
Summary: Invalid "no enclosing type" error
Status: RESOLVED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 3.0 M9   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-04-29 11:25 EDT by John Arthorne CLA
Modified: 2004-04-29 15:58 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 John Arthorne CLA 2004-04-29 11:25:20 EDT
I20040427

The following test case has a compile error on the reference to "I.this" inside
the anonymous implementation of I. It says there is no enclosing instance of
type I. This is not true, since the anonymous type itself is of type I. An
unqualified "this" reference compiles fine.

public class A {
	interface I {
		public void doit();
	}
	public void foo(I i) {
	}
	public void bar() {
		new I() {
			public void doit() {
				foo(I.this);
			}
		};
	}
}
Comment 1 Olivier Thomann CLA 2004-04-29 11:50:06 EDT
I renamed the class X, and I compiled it using javac 1.4.2 and jikes 1.18.
Both also report an error in this case:

javac 1.4.2:
X.java:10: not an enclosing class: X.I
                                foo(I.this);
                                     ^
1 error

jikes 1.18:
Found 1 semantic error compiling "C:/tests_sources/X.java":

    10.                                 foo(I.this);
                                            ^
*** Semantic Error: Interface "X$I" cannot be used where a class is expected.
Comment 2 John Arthorne CLA 2004-04-29 14:12:34 EDT
Feel free to close if you think the current behaviour is correct.  It just
seemed wrong to me.
Comment 3 Philipe Mulet CLA 2004-04-29 15:58:32 EDT
The message is a little cryptic, however the rule is that you cannot qualify an 
enclosing type with a supertype. It has to match exactly one of the enclosing 
type name.
Given it is an anonymous. this and A.this would be legite. I is only a 
supertype of the anonymous type.