View | Details | Raw Unified | Return to bug 312076 | Differences between
and this patch

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/ast/ClassLiteralAccess.java (+10 lines)
Lines 77-82 Link Here
77
		this.constant = Constant.NotAConstant;
77
		this.constant = Constant.NotAConstant;
78
		if ((this.targetType = this.type.resolveType(scope, true /* check bounds*/)) == null)
78
		if ((this.targetType = this.type.resolveType(scope, true /* check bounds*/)) == null)
79
			return null;
79
			return null;
80
		
81
		/* https://bugs.eclipse.org/bugs/show_bug.cgi?id=320463
82
		   https://bugs.eclipse.org/bugs/show_bug.cgi?id=312076
83
		   JLS3 15.8.2 forbids the type named in the class literal expression from being a parameterized type.
84
		   And the grammar in 18.1 disallows (where X and Y are some concrete types) constructs of the form
85
		   Outer<X>.class, Outer<X>.Inner.class, Outer.Inner<X>.class, Outer<X>.Inner<Y>.class etc.
86
		   Corollary wise, we should resolve the type of the class literal expression to be a raw type as
87
		   class literals exist only for the raw underlying type. 
88
		 */
89
		this.targetType = scope.environment().convertToRawType(this.targetType, true /* force conversion of enclosing types*/);
80
90
81
		if (this.targetType.isArrayType()) {
91
		if (this.targetType.isArrayType()) {
82
			ArrayBinding arrayBinding = (ArrayBinding) this.targetType;
92
			ArrayBinding arrayBinding = (ArrayBinding) this.targetType;
(-)src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java (-1 / +75 lines)
Lines 50576-50580 Link Here
50576
			},
50576
			},
50577
			"");
50577
			"");
50578
}
50578
}
50579
50579
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=320463
50580
public void test1466() {
50581
	this.runNegativeTest(
50582
		new String[] {
50583
			"Outer.java",
50584
			"public class Outer<T> {\n"+
50585
			"    class Cell {\n"+
50586
			"        final T value;\n"+
50587
			"        Cell(T value) {\n"+
50588
			"            this.value = value;\n"+
50589
			"        }\n"+
50590
			"    }\n"+
50591
			"    Class<Outer<T>.Cell> cellClass = Cell.class;\n"+
50592
			"    {\n"+
50593
			"    	this.cellClass = Cell.class;\n"+
50594
			"    	this.cellClass = Outer.Cell.class;\n"+
50595
			"    }\n"+
50596
			"    public static void main(String[] args) {\n"+
50597
			"        Outer<Integer>.Cell intCell = new Outer<Integer>().new Cell(314);\n"+
50598
			"        Outer<String>.Cell strCell = new Outer<String>().cellClass.cast(intCell);\n"+
50599
			"        String val = strCell.value; // ClassCastException\n"+
50600
			"        System.out.println(val);\n"+
50601
			"    }\n"+
50602
			"}\n"
50603
		},
50604
		"----------\n" + 
50605
		"1. ERROR in Outer.java (at line 8)\n" + 
50606
		"	Class<Outer<T>.Cell> cellClass = Cell.class;\n" + 
50607
		"	                                 ^^^^^^^^^^\n" + 
50608
		"Type mismatch: cannot convert from Class<Outer.Cell> to Class<Outer<T>.Cell>\n" + 
50609
		"----------\n" + 
50610
		"2. ERROR in Outer.java (at line 10)\n" + 
50611
		"	this.cellClass = Cell.class;\n" + 
50612
		"	                 ^^^^^^^^^^\n" + 
50613
		"Type mismatch: cannot convert from Class<Outer.Cell> to Class<Outer<T>.Cell>\n" + 
50614
		"----------\n" + 
50615
		"3. ERROR in Outer.java (at line 11)\n" + 
50616
		"	this.cellClass = Outer.Cell.class;\n" + 
50617
		"	                 ^^^^^^^^^^^^^^^^\n" + 
50618
		"Type mismatch: cannot convert from Class<Outer.Cell> to Class<Outer<T>.Cell>\n" + 
50619
		"----------\n");
50620
}
50621
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=312076
50622
public void test1467() {
50623
	this.runNegativeTest(
50624
		new String[] {
50625
			"X.java",
50626
			"public class X<T>  { \n" +
50627
			"    public abstract static class Base<S extends Base<S>> {\n" +
50628
			"        public Base(Class<S> sClass) {\n" +
50629
			"            Class<S> theClass = sClass;\n" +
50630
			"            System.out.println(theClass);\n" +
50631
			"            System.out.println(sClass);\n" +
50632
			"        }\n" +
50633
			"    }\n" +
50634
			"    public class Arr extends Base<Arr> {\n" +
50635
			"        public Arr() { \n" +
50636
			"            super(Arr.class);\n" +
50637
			"            System.out.println(Arr.class);\n" +
50638
			"        }\n" +
50639
			"    }\n" +
50640
			"    public static void main(String[] args) {\n" +
50641
			"        X<Integer> x = new X<Integer>();\n" +
50642
			"        X<Integer>.Arr a = x.new Arr();\n" +
50643
			"        System.out.println(a);\n" +
50644
			"    }\n" +
50645
			"}\n"
50646
		},
50647
		"----------\n" + 
50648
		"1. ERROR in X.java (at line 11)\n" + 
50649
		"	super(Arr.class);\n" + 
50650
		"	^^^^^^^^^^^^^^^^^\n" + 
50651
		"The constructor X.Base<X<T>.Arr>(Class<X.Arr>) is undefined\n" + 
50652
		"----------\n");
50653
}
50580
}
50654
}

Return to bug 312076