Bug 183216 - [1.5][compiler] Cannot refer to a generic member type using a non static subclass of the enclosing type
Summary: [1.5][compiler] Cannot refer to a generic member type using a non static subc...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.3 M7   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-04-19 12:17 EDT by Olivier Thomann CLA
Modified: 2007-04-27 10:54 EDT (History)
0 users

See Also:


Attachments
Proposed patch (28.23 KB, patch)
2007-04-24 06:55 EDT, Philipe Mulet CLA
no flags Details | Diff
Better patch (30.46 KB, patch)
2007-04-24 10:39 EDT, Philipe Mulet CLA
no flags Details | Diff
Proposed patch for 3.2.2 (12.87 KB, patch)
2007-04-24 10:40 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 Olivier Thomann CLA 2007-04-19 12:17:45 EDT
Using v_749, the following code doesn't compile:

class A {
    class B<T> {
        T t;
        T getValue() {
            return t;
        }
    }
}

class C<T> extends A {
}

public class X {
    static C.B<Double> c = new C().new B<Double>();

    public static void main(String[] args) {
        C.B<String> temp = new C().new B<String>();
        String s = temp.getValue();
        System.out.println(s);
        foo(bar());
    }

    static C.B<? extends Number> bar() {
        return new C().new B<Integer>();
    }

    static void foo(C.B<?> arg) {
        Object o = arg.getValue();
        Double d = c.getValue();
        System.out.println(o);
        System.out.println(d);
    }
}

giving these errors and warnings:

----------
1. ERROR in D:\tests_sources\X.java (at line 14)
	static C.B<Double> c = new C().new B<Double>();
	       ^^^
The member type C.B<Double> must be qualified with a parameterized type, since it is not static
----------
2. WARNING in D:\tests_sources\X.java (at line 14)
	static C.B<Double> c = new C().new B<Double>();
	                           ^
C is a raw type. References to generic type C<T> should be parameterized
----------
3. ERROR in D:\tests_sources\X.java (at line 14)
	static C.B<Double> c = new C().new B<Double>();
	                                   ^
The member type C.B<Double> must be qualified with a parameterized type, since it is not static
----------
4. ERROR in D:\tests_sources\X.java (at line 17)
	C.B<String> temp = new C().new B<String>();
	^^^
The member type C.B<String> must be qualified with a parameterized type, since it is not static
----------
5. WARNING in D:\tests_sources\X.java (at line 17)
	C.B<String> temp = new C().new B<String>();
	                       ^
C is a raw type. References to generic type C<T> should be parameterized
----------
6. ERROR in D:\tests_sources\X.java (at line 17)
	C.B<String> temp = new C().new B<String>();
	                               ^
The member type C.B<String> must be qualified with a parameterized type, since it is not static
----------
7. ERROR in D:\tests_sources\X.java (at line 23)
	static C.B<? extends Number> bar() {
	       ^^^
The member type C.B<? extends Number> must be qualified with a parameterized type, since it is not static
----------
8. WARNING in D:\tests_sources\X.java (at line 24)
	return new C().new B<Integer>();
	           ^
C is a raw type. References to generic type C<T> should be parameterized
----------
9. ERROR in D:\tests_sources\X.java (at line 24)
	return new C().new B<Integer>();
	                   ^
The member type C.B<Integer> must be qualified with a parameterized type, since it is not static
----------
10. ERROR in D:\tests_sources\X.java (at line 27)
	static void foo(C.B<?> arg) {
	                ^^^
The member type C.B<?> must be qualified with a parameterized type, since it is not static
----------
10 problems (7 errors, 3 warnings)

whereas this one compiles fine:

class A {
    class B<T> {
        T t;
        T getValue() {
            return t;
        }
    }
}

public class X {
    static A.B<Double> c = new A().new B<Double>();

    public static void main(String[] args) {
        A.B<String> temp = new A().new B<String>();
        String s = temp.getValue();
        System.out.println(s);
        foo(bar());
    }

    static A.B<? extends Number> bar() {
        return new A().new B<Integer>();
    }

    static void foo(A.B<?> arg) {
        Object o = arg.getValue();
        Double d = c.getValue();
        System.out.println(o);
        System.out.println(d);
    }
}

javac compiles both cases without reporting any error, not even a warning.
Comment 1 Philipe Mulet CLA 2007-04-24 06:55:10 EDT
Created attachment 64713 [details]
Proposed patch
Comment 2 Philipe Mulet CLA 2007-04-24 10:39:47 EDT
Created attachment 64742 [details]
Better patch
Comment 3 Philipe Mulet CLA 2007-04-24 10:40:15 EDT
Created attachment 64743 [details]
Proposed patch for 3.2.2
Comment 4 Philipe Mulet CLA 2007-04-24 10:41:21 EDT
Added GenericTypeTest#test1124-1128

Released for 3.3M7
Comment 5 Philipe Mulet CLA 2007-04-24 10:45:17 EDT
Released for 3.2 maintenance.
Comment 6 Jerome Lanneluc CLA 2007-04-27 10:54:59 EDT
Verified for 3.3M7 with I20070427-0010