Community
Participate
Working Groups
When trying to compile the following piece of code #### public class TestGenerics<E> { public static class InnerClass { public InnerClass() { System.out.println("class : " + InnerClass.this); } } } #### 3.1RC2 shows the error "No enclosing instance of the type TestGenerics.InnerClass is accessible in scope". The same error is given when using 3.1M7 and 3.1RC1, but javac accepts this piece of code without any complaints. The error disappears when the generic parameter is removed from the outer class as well as the qualified access to the instance of the inner class is removed.
We were unwrapping raw types, but hadn't think of parameterized case. Fix is simple, always reach the erased type. Added GenericTypeTest#test763 +1 for RC3. Simple fix. Dirk - can you vote for it ?
Fix is: Index: QualifiedThisReference.java =================================================================== RCS file: /home/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedThisReference.java,v retrieving revision 1.31 diff -u -r1.31 QualifiedThisReference.java --- QualifiedThisReference.java 23 Feb 2005 02:47:28 -0000 1.31 +++ QualifiedThisReference.java 17 Jun 2005 09:19:18 -0000 @@ -72,15 +72,13 @@ public TypeBinding resolveType(BlockScope scope) { constant = NotAConstant; - TypeBinding type = this.resolvedType = this.qualification.resolveType(scope, true /* check bounds*/); + TypeBinding type = this.qualification.resolveType(scope, true /* check bounds*/); if (type == null) return null; - // X.this is not a raw type as denoting enclosing instance - if (type.isRawType()) { - RawTypeBinding rawType = (RawTypeBinding) type; - type = this.resolvedType = rawType.type; // unwrap - } + // X.this is not a param/raw type as denoting enclosing instance + this.resolvedType = type = type.erasure(); + // the qualification MUST exactly match some enclosing type name - // Its possible to qualify 'this' by the name of the current class + // It is possible to qualify 'this' by the name of the current class int depth = 0; this.currentCompatibleType = scope.referenceType().binding; while (this.currentCompatibleType != null
+1 for RC3.
fixed
Created attachment 23463 [details] Augmented test case. Shows that the fix covers other cases than the initial test case. Checked that behavior is the same as javac. Invalidated _test763d shows a slight difference in compiler error messages semantics between javac and jdt.core, for which I open a separate bug.
Verified using Build id: I20050617-0010 + JDT Core HEAD.
Verified with I20050617-1227