Bug 142897 - [1.5][compiler] Compiler cannot resolve type of inner class of a bounded generic type
Summary: [1.5][compiler] Compiler cannot resolve type of inner class of a bounded gene...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 3.2.1   Edit
Assignee: Kent Johnson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 241710 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-05-20 14:59 EDT by Rafael de F. Ferreira CLA
Modified: 2008-09-10 11:18 EDT (History)
2 users (show)

See Also:


Attachments
Patch for the tests (10.17 KB, patch)
2006-05-29 11:17 EDT, Philipe Mulet CLA
no flags Details | Diff
Proposed patch (7.25 KB, patch)
2006-05-29 11:24 EDT, Philipe Mulet CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Rafael de F. Ferreira CLA 2006-05-20 14:59:08 EDT
The following code compiles normally in JDK 1.5.0_06, but fails in Eclipse 3.2RC3 (build id I20060505-1306), with a "T.Inner cannot be resolved to a type" error located at the line marked with a //** comment.

package p1;

public class Outer {
  public class Inner {
     
  }
}

class ATest<T extends Outer> {
   public ATest() {
      T instance = makeInstance();
      Outer.Inner peq = instance.new Inner(); //**
   }

   private T makeInstance() {
      return (T) new Outer();
   }
}
Comment 1 Philipe Mulet CLA 2006-05-21 15:02:21 EDT
Javac 1.6 agrees with us:
Outer.java:10: cannot select from a type variable
      Outer.Inner peq = instance.new Inner(); //**
                                 ^
Outer.java:14: warning: [unchecked] unchecked cast
found   : Outer
required: T
      return (T) new Outer();
                 ^
1 error
1 warning
Comment 2 Rafael de F. Ferreira CLA 2006-05-21 16:46:45 EDT
(In reply to comment #1)

So, this means that the bug likely is in Javac 5? I tried looking it up in the the Java lang spec, but it's a bit over my head... 
Comment 3 Philipe Mulet CLA 2006-05-22 03:11:48 EDT
Yes, this would be a javac bug in 1.5.

Added GenericTypeTest#test0993
Comment 4 Philipe Mulet CLA 2006-05-22 03:22:16 EDT
Our error message may be slightly improved, along the line of bug 128423
Comment 5 Philipe Mulet CLA 2006-05-22 05:03:20 EDT
I am not seeing either any argument against it in the spec. 
In 4.4, it claims: 
"The members of a type variable X with bound T & I1 ... In are the members
of the intersection type (§4.9) T & I1 ... In appearing at the point where the type variable is declared."

Then in 4.9, last bullet:
"• Then the intersection type has the same members as a class type (§8) with an
empty body, direct superclass Ck and direct superinterfaces IT1 , ..., ITn,
declared in the same package in which the intersection type appears."
Comment 6 Philipe Mulet CLA 2006-05-22 07:20:55 EDT
Added GenericTypeTest#test0994
Comment 7 Philipe Mulet CLA 2006-05-29 04:42:26 EDT
Member types should be reachable through type variables, and got disallowed when addressing bug 128423 (3.2RC1).
Comment 8 Philipe Mulet CLA 2006-05-29 05:02:35 EDT
Also added GenericTypeTest#test0997
Comment 9 Philipe Mulet CLA 2006-05-29 11:17:28 EDT
Created attachment 42869 [details]
Patch for the tests
Comment 10 Philipe Mulet CLA 2006-05-29 11:24:19 EDT
Created attachment 42870 [details]
Proposed patch

Patch is re-enabling finding member types through type variables,
also needs to tackle reentering connect type hierarchies algorithm.
Comment 11 Philipe Mulet CLA 2006-05-29 11:43:13 EDT
Released GenericTypeTest, with new tests disabled:
test0229 - expectation should change, new behavior guarded by "if (false)"
test0306 - expectation should change, new behavior guarded by "if (false)"
_test0917a - to be enabled
_test0993 - to be enabled
_test0994 - to be enabled
_test0995 - to be enabled
_test0997 - to be enabled
Comment 12 Kent Johnson CLA 2006-06-05 13:40:51 EDT
I think case 917 & 917a should report that you cannot access anything from the type variable while connecting its class' hierarchy.

In 1.5, case 917 currently causes a walkback and in 1.6, it reports that you cannot select from a type variable.

Philippe, are you sure these cases should be changed?
Comment 13 Philipe Mulet CLA 2006-06-06 10:43:24 EDT
Ok to not resolve them in type hierarchies. Note that javac confessed bugs in this area, will see how things evolve in the future.
Comment 14 Kent Johnson CLA 2006-06-06 12:49:49 EDT
Released new fix and enabled Generic type tests
Comment 15 Frederic Fusier CLA 2006-06-12 06:17:48 EDT
Released for 3.2.1
Released for 3.3 M1 while merging TARGET_321 in HEAD
Comment 16 Frederic Fusier CLA 2006-08-07 11:06:08 EDT
Verified for 3.3 M1 using build I20060807-0010.
Comment 17 Frederic Fusier CLA 2006-09-12 08:26:56 EDT
Verified for 3.2.1 using build M20060908-1655.
Comment 18 Kent Johnson CLA 2008-09-10 11:18:31 EDT
*** Bug 241710 has been marked as a duplicate of this bug. ***