Bug 100519 - [1.5][compiler] generic parameter and qualified access seems to confuse each other
Summary: [1.5][compiler] generic parameter and qualified access seems to confuse each ...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 RC3   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-06-17 02:42 EDT by Tobias Riemenschneider CLA
Modified: 2005-06-17 14:06 EDT (History)
1 user (show)

See Also:


Attachments
Augmented test case. (8.77 KB, patch)
2005-06-17 12:54 EDT, Maxime Daniel CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Riemenschneider CLA 2005-06-17 02:42:25 EDT
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.
Comment 1 Philipe Mulet CLA 2005-06-17 05:18:37 EDT
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 ?
Comment 2 Philipe Mulet CLA 2005-06-17 05:19:14 EDT
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
Comment 3 Dirk Baeumer CLA 2005-06-17 05:24:55 EDT
+1 for RC3.
Comment 4 Philipe Mulet CLA 2005-06-17 05:25:16 EDT
fixed
Comment 5 Maxime Daniel CLA 2005-06-17 12:54:05 EDT
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.
Comment 6 Maxime Daniel CLA 2005-06-17 13:06:52 EDT
Verified using Build id: I20050617-0010 + JDT Core HEAD.
Comment 7 Olivier Thomann CLA 2005-06-17 14:06:38 EDT
Verified with I20050617-1227