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

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java (+214 lines)
Lines 40592-40596 Link Here
40592
			"	     ^^^^^^\n" + 
40592
			"	     ^^^^^^\n" + 
40593
			"Unused type arguments for the non generic constructor Local() of type Local; it should not be parameterized with arguments <String>\n" + 
40593
			"Unused type arguments for the non generic constructor Local() of type Local; it should not be parameterized with arguments <String>\n" + 
40594
			"----------\n");
40594
			"----------\n");
40595
}
40596
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=208873
40597
public void test1212() {
40598
	this.runConformTest(
40599
		new String[] {
40600
			"X.java",
40601
			"public class X {\n" + 
40602
			"	public interface Loader {\n" + 
40603
			"		public <T extends Integer, K extends String> T load(final K key);\n" + 
40604
			"	}\n" + 
40605
			"	Loader loader;\n" + 
40606
			"	public <K extends String, T extends Integer> T get(final K key) {\n" + 
40607
			"		T data = this.loader.load(key);\n" + 
40608
			"		return null;\n" + 
40609
			"	}\n" + 
40610
			"}\n", // =================
40611
		},
40612
		"");
40613
}
40614
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=208873 - variation
40615
public void test1213() {
40616
	this.runConformTest(
40617
		new String[] {
40618
			"X.java",
40619
			"public class X {\n" + 
40620
			"    <T, U extends T, V extends T> T cond1(boolean z, U x1, V x2) {\n" + 
40621
			"        return (z? x1: x2);\n" + 
40622
			"    }\n" + 
40623
			"}\n",
40624
		},
40625
		"");
40626
}	
40627
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209153
40628
public void test1214() {
40629
	this.runNegativeTest(
40630
		new String[] {
40631
			"X.java",
40632
			"public class X {\n" + 
40633
			"	public static void main(String[] args) {\n" + 
40634
			"		p.A myA = new p.A();\n" + 
40635
			"		myA.p = myA.box.get(); // [msgSend] generic cast to P -> error\n" + 
40636
			"		Object o = myA.box.get(); // ok, since no generic cast actually inserted\n" + 
40637
			"		myA.p = myA.getBox().t;// [fieldRef] generic cast to P -> error\n" + 
40638
			"		myA.p = myA.box.t;// [qName] generic cast to P -> error\n" + 
40639
			"		int pval = myA.box.t.pval;// intermediate access through P already flagged as error\n" + 
40640
			"	}\n" + 
40641
			"}\n",
40642
			"p/A.java",
40643
			"package p;\n" + 
40644
			"public class A {\n" + 
40645
			"	public static class Box<T> {\n" + 
40646
			"		public T t;\n" + 
40647
			"		public void set(T t) { this.t = t; }\n" + 
40648
			"		public T get()	{ return this.t; }\n" + 
40649
			"	}\n" + 
40650
			"	private class P {\n" + 
40651
			"		public int pval;\n" + 
40652
			"	}\n" + 
40653
			"	public P p;\n" + 
40654
			"	public Box<P> box;\n" + 
40655
			"	public Box<P> getBox() { return this.box; }\n" + 
40656
			"	public A next;\n" + 
40657
			"	public A getNext() { return this;} \n" + 
40658
			"	public A() {\n" + 
40659
			"		this.box = new Box<P>();\n" + 
40660
			"		this.box.set(new P());\n" + 
40661
			"	}\n" + 
40662
			"}\n"
40663
		},
40664
		"----------\n" + 
40665
		"1. ERROR in X.java (at line 4)\n" + 
40666
		"	myA.p = myA.box.get(); // [msgSend] generic cast to P -> error\n" + 
40667
		"	        ^^^^^^^^^^^^^\n" + 
40668
		"The type A.P is not visible\n" + 
40669
		"----------\n" + 
40670
		"2. ERROR in X.java (at line 6)\n" + 
40671
		"	myA.p = myA.getBox().t;// [fieldRef] generic cast to P -> error\n" + 
40672
		"	        ^^^^^^^^^^^^^^\n" + 
40673
		"The type A.P is not visible\n" + 
40674
		"----------\n" + 
40675
		"3. ERROR in X.java (at line 7)\n" + 
40676
		"	myA.p = myA.box.t;// [qName] generic cast to P -> error\n" + 
40677
		"	        ^^^\n" + 
40678
		"The type A.P is not visible\n" + 
40679
		"----------\n" + 
40680
		"4. ERROR in X.java (at line 8)\n" + 
40681
		"	int pval = myA.box.t.pval;// intermediate access through P already flagged as error\n" + 
40682
		"	           ^^^^^^^^^^^^^^\n" + 
40683
		"The type A.P is not visible\n" + 
40684
		"----------\n" + 
40685
		"----------\n" + 
40686
		"1. WARNING in p\\A.java (at line 18)\n" + 
40687
		"	this.box.set(new P());\n" + 
40688
		"	             ^^^^^^^\n" + 
40689
		"Access to enclosing constructor A.P() is emulated by a synthetic accessor method. Increasing its visibility will improve your performance\n" + 
40690
		"----------\n");
40691
}	
40692
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209153 - variation
40693
public void test1215() {
40694
	this.runNegativeTest(
40695
		new String[] {
40696
			"X.java",
40697
			"public class X {\n" + 
40698
			"	public static void main(String[] args) {\n" + 
40699
			"		p.A myA = new p.A();\n" + 
40700
			"		myA.p = myA.box.get(); // [msgSend] generic cast to P -> error\n" + 
40701
			"		Object o = myA.box.get(); // ok, since no generic cast actually inserted\n" + 
40702
			"		myA.p = myA.getBox().t;// [fieldRef] generic cast to P -> error\n" + 
40703
			"		myA.p = myA.box.t;// [qName] generic cast to P -> error\n" + 
40704
			"		int pval = myA.box.t.pval;// intermediate access through P already flagged as error\n" + 
40705
			"	}\n" + 
40706
			"}\n",
40707
			"p/A.java",
40708
			"package p;\n" + 
40709
			"public class A {\n" + 
40710
			"	public static class Box<T> {\n" + 
40711
			"		public T t;\n" + 
40712
			"		public void set(T t) { this.t = t; }\n" + 
40713
			"		public T get()	{ return this.t; }\n" + 
40714
			"	}\n" + 
40715
			"	protected class P {\n" + 
40716
			"		public int pval;\n" + 
40717
			"	}\n" + 
40718
			"	public P p;\n" + 
40719
			"	public Box<P> box;\n" + 
40720
			"	public Box<P> getBox() { return this.box; }\n" + 
40721
			"	public A next;\n" + 
40722
			"	public A getNext() { return this;} \n" + 
40723
			"	public A() {\n" + 
40724
			"		this.box = new Box<P>();\n" + 
40725
			"		this.box.set(new P());\n" + 
40726
			"	}\n" + 
40727
			"}\n"
40728
		},
40729
		"----------\n" + 
40730
		"1. ERROR in X.java (at line 4)\n" + 
40731
		"	myA.p = myA.box.get(); // [msgSend] generic cast to P -> error\n" + 
40732
		"	        ^^^^^^^^^^^^^\n" + 
40733
		"The type A.P is not visible\n" + 
40734
		"----------\n" + 
40735
		"2. ERROR in X.java (at line 6)\n" + 
40736
		"	myA.p = myA.getBox().t;// [fieldRef] generic cast to P -> error\n" + 
40737
		"	        ^^^^^^^^^^^^^^\n" + 
40738
		"The type A.P is not visible\n" + 
40739
		"----------\n" + 
40740
		"3. ERROR in X.java (at line 7)\n" + 
40741
		"	myA.p = myA.box.t;// [qName] generic cast to P -> error\n" + 
40742
		"	        ^^^\n" + 
40743
		"The type A.P is not visible\n" + 
40744
		"----------\n" + 
40745
		"4. ERROR in X.java (at line 8)\n" + 
40746
		"	int pval = myA.box.t.pval;// intermediate access through P already flagged as error\n" + 
40747
		"	           ^^^^^^^^^^^^^^\n" + 
40748
		"The type A.P is not visible\n" + 
40749
		"----------\n");
40750
}	
40751
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209153 - variation
40752
public void test1216() {
40753
	this.runNegativeTest(
40754
		new String[] {
40755
			"X.java",
40756
			"public class X {\n" + 
40757
			"	public static void main(String[] args) {\n" + 
40758
			"		p.A myA = new p.A();\n" + 
40759
			"		myA.p = myA.box.get(); // [msgSend] generic cast to P -> error\n" + 
40760
			"		Object o = myA.box.get(); // ok, since no generic cast actually inserted\n" + 
40761
			"		myA.p = myA.getBox().t;// [fieldRef] generic cast to P -> error\n" + 
40762
			"		myA.p = myA.box.t;// [qName] generic cast to P -> error\n" + 
40763
			"		int pval = myA.box.t.pval;// intermediate access through P already flagged as error\n" + 
40764
			"	}\n" + 
40765
			"}\n",
40766
			"p/A.java",
40767
			"package p;\n" + 
40768
			"public class A {\n" + 
40769
			"	public static class Box<T> {\n" + 
40770
			"		public T t;\n" + 
40771
			"		public void set(T t) { this.t = t; }\n" + 
40772
			"		public T get()	{ return this.t; }\n" + 
40773
			"	}\n" + 
40774
			"	class P {\n" + 
40775
			"		public int pval;\n" + 
40776
			"	}\n" + 
40777
			"	public P p;\n" + 
40778
			"	public Box<P> box;\n" + 
40779
			"	public Box<P> getBox() { return this.box; }\n" + 
40780
			"	public A next;\n" + 
40781
			"	public A getNext() { return this;} \n" + 
40782
			"	public A() {\n" + 
40783
			"		this.box = new Box<P>();\n" + 
40784
			"		this.box.set(new P());\n" + 
40785
			"	}\n" + 
40786
			"}\n"
40787
		},
40788
		"----------\n" + 
40789
		"1. ERROR in X.java (at line 4)\n" + 
40790
		"	myA.p = myA.box.get(); // [msgSend] generic cast to P -> error\n" + 
40791
		"	        ^^^^^^^^^^^^^\n" + 
40792
		"The type A.P is not visible\n" + 
40793
		"----------\n" + 
40794
		"2. ERROR in X.java (at line 6)\n" + 
40795
		"	myA.p = myA.getBox().t;// [fieldRef] generic cast to P -> error\n" + 
40796
		"	        ^^^^^^^^^^^^^^\n" + 
40797
		"The type A.P is not visible\n" + 
40798
		"----------\n" + 
40799
		"3. ERROR in X.java (at line 7)\n" + 
40800
		"	myA.p = myA.box.t;// [qName] generic cast to P -> error\n" + 
40801
		"	        ^^^\n" + 
40802
		"The type A.P is not visible\n" + 
40803
		"----------\n" + 
40804
		"4. ERROR in X.java (at line 8)\n" + 
40805
		"	int pval = myA.box.t.pval;// intermediate access through P already flagged as error\n" + 
40806
		"	           ^^^^^^^^^^^^^^\n" + 
40807
		"The type A.P is not visible\n" + 
40808
		"----------\n");
40595
}	
40809
}	
40596
}
40810
}
(-)compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java (+11 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.ast;
11
package org.eclipse.jdt.internal.compiler.ast;
12
12
13
import org.eclipse.jdt.core.compiler.CharOperation;
13
import org.eclipse.jdt.internal.compiler.ASTVisitor;
14
import org.eclipse.jdt.internal.compiler.ASTVisitor;
14
import org.eclipse.jdt.internal.compiler.impl.*;
15
import org.eclipse.jdt.internal.compiler.impl.*;
15
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
16
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
Lines 228-233 Link Here
228
		    		? compileTimeType  // unboxing: checkcast before conversion
229
		    		? compileTimeType  // unboxing: checkcast before conversion
229
		    		: runtimeTimeType;
230
		    		: runtimeTimeType;
230
		        this.genericCast = originalType.genericCast(scope.boxing(targetType));
231
		        this.genericCast = originalType.genericCast(scope.boxing(targetType));
232
		        if (this.genericCast instanceof ReferenceBinding) {
233
					ReferenceBinding referenceCast = (ReferenceBinding) this.genericCast;
234
					if (!referenceCast.canBeSeenBy(scope)) {
235
			        	scope.problemReporter().invalidType(this, 
236
			        			new ProblemReferenceBinding(
237
									CharOperation.splitOn('.', referenceCast.shortReadableName()),
238
									referenceCast,
239
									ProblemReasons.NotVisible));
240
					}
241
		        }				        
231
			} 	
242
			} 	
232
		}
243
		}
233
		super.computeConversion(scope, runtimeTimeType, compileTimeType);
244
		super.computeConversion(scope, runtimeTimeType, compileTimeType);
(-)compiler/org/eclipse/jdt/internal/compiler/ast/FieldReference.java (+11 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.ast;
11
package org.eclipse.jdt.internal.compiler.ast;
12
12
13
import org.eclipse.jdt.core.compiler.CharOperation;
13
import org.eclipse.jdt.internal.compiler.ASTVisitor;
14
import org.eclipse.jdt.internal.compiler.ASTVisitor;
14
import org.eclipse.jdt.internal.compiler.impl.*;
15
import org.eclipse.jdt.internal.compiler.impl.*;
15
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
16
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
Lines 127-132 Link Here
127
	    		? compileTimeType  // unboxing: checkcast before conversion
128
	    		? compileTimeType  // unboxing: checkcast before conversion
128
	    		: runtimeTimeType;
129
	    		: runtimeTimeType;
129
	        this.genericCast = originalBinding.type.genericCast(targetType);
130
	        this.genericCast = originalBinding.type.genericCast(targetType);
131
	        if (this.genericCast instanceof ReferenceBinding) {
132
				ReferenceBinding referenceCast = (ReferenceBinding) this.genericCast;
133
				if (!referenceCast.canBeSeenBy(scope)) {
134
		        	scope.problemReporter().invalidType(this, 
135
		        			new ProblemReferenceBinding(
136
								CharOperation.splitOn('.', referenceCast.shortReadableName()),
137
								referenceCast,
138
								ProblemReasons.NotVisible));
139
				}
140
	        }			        
130
		}
141
		}
131
	} 	
142
	} 	
132
	super.computeConversion(scope, runtimeTimeType, compileTimeType);
143
	super.computeConversion(scope, runtimeTimeType, compileTimeType);
(-)compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java (-1 / +12 lines)
Lines 27-32 Link Here
27
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
27
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
28
import org.eclipse.jdt.internal.compiler.lookup.ProblemMethodBinding;
28
import org.eclipse.jdt.internal.compiler.lookup.ProblemMethodBinding;
29
import org.eclipse.jdt.internal.compiler.lookup.ProblemReasons;
29
import org.eclipse.jdt.internal.compiler.lookup.ProblemReasons;
30
import org.eclipse.jdt.internal.compiler.lookup.ProblemReferenceBinding;
30
import org.eclipse.jdt.internal.compiler.lookup.RawTypeBinding;
31
import org.eclipse.jdt.internal.compiler.lookup.RawTypeBinding;
31
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
32
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
32
import org.eclipse.jdt.internal.compiler.lookup.Scope;
33
import org.eclipse.jdt.internal.compiler.lookup.Scope;
Lines 98-104 Link Here
98
	    	TypeBinding targetType = (!compileTimeType.isBaseType() && runtimeTimeType.isBaseType()) 
99
	    	TypeBinding targetType = (!compileTimeType.isBaseType() && runtimeTimeType.isBaseType()) 
99
	    		? compileTimeType  // unboxing: checkcast before conversion
100
	    		? compileTimeType  // unboxing: checkcast before conversion
100
	    		: runtimeTimeType;
101
	    		: runtimeTimeType;
101
	        this.valueCast = originalType.genericCast(targetType); 
102
	        this.valueCast = originalType.genericCast(targetType);
102
		} 	else if (this.actualReceiverType.isArrayType() 
103
		} 	else if (this.actualReceiverType.isArrayType() 
103
						&& runtimeTimeType.id != TypeIds.T_JavaLangObject
104
						&& runtimeTimeType.id != TypeIds.T_JavaLangObject
104
						&& this.binding.parameters == Binding.NO_PARAMETERS 
105
						&& this.binding.parameters == Binding.NO_PARAMETERS 
Lines 107-112 Link Here
107
					// from 1.5 compliant mode on, array#clone() resolves to array type, but codegen to #clone()Object - thus require extra inserted cast
108
					// from 1.5 compliant mode on, array#clone() resolves to array type, but codegen to #clone()Object - thus require extra inserted cast
108
			this.valueCast = runtimeTimeType;			
109
			this.valueCast = runtimeTimeType;			
109
		}
110
		}
111
        if (this.valueCast instanceof ReferenceBinding) {
112
			ReferenceBinding referenceCast = (ReferenceBinding) this.valueCast;
113
			if (!referenceCast.canBeSeenBy(scope)) {
114
	        	scope.problemReporter().invalidType(this, 
115
	        			new ProblemReferenceBinding(
116
							CharOperation.splitOn('.', referenceCast.shortReadableName()),
117
							referenceCast,
118
							ProblemReasons.NotVisible));
119
			}
120
        }		
110
	}
121
	}
111
	super.computeConversion(scope, runtimeTimeType, compileTimeType);
122
	super.computeConversion(scope, runtimeTimeType, compileTimeType);
112
}
123
}
(-)compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedNameReference.java (-1 / +14 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.ast;
11
package org.eclipse.jdt.internal.compiler.ast;
12
12
13
import org.eclipse.jdt.core.compiler.CharOperation;
13
import org.eclipse.jdt.internal.compiler.ASTVisitor;
14
import org.eclipse.jdt.internal.compiler.ASTVisitor;
14
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
15
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
15
import org.eclipse.jdt.internal.compiler.codegen.CodeStream;
16
import org.eclipse.jdt.internal.compiler.codegen.CodeStream;
Lines 25-30 Link Here
25
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
26
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
26
import org.eclipse.jdt.internal.compiler.lookup.MethodScope;
27
import org.eclipse.jdt.internal.compiler.lookup.MethodScope;
27
import org.eclipse.jdt.internal.compiler.lookup.ProblemFieldBinding;
28
import org.eclipse.jdt.internal.compiler.lookup.ProblemFieldBinding;
29
import org.eclipse.jdt.internal.compiler.lookup.ProblemReasons;
28
import org.eclipse.jdt.internal.compiler.lookup.ProblemReferenceBinding;
30
import org.eclipse.jdt.internal.compiler.lookup.ProblemReferenceBinding;
29
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
31
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
30
import org.eclipse.jdt.internal.compiler.lookup.Scope;
32
import org.eclipse.jdt.internal.compiler.lookup.Scope;
Lines 351-357 Link Here
351
	    	TypeBinding targetType = (!compileTimeType.isBaseType() && runtimeTimeType.isBaseType()) 
353
	    	TypeBinding targetType = (!compileTimeType.isBaseType() && runtimeTimeType.isBaseType()) 
352
	    		? compileTimeType  // unboxing: checkcast before conversion
354
	    		? compileTimeType  // unboxing: checkcast before conversion
353
	    		: runtimeTimeType;
355
	    		: runtimeTimeType;
354
	    	setGenericCast(length, originalType.genericCast(targetType));
356
	    	TypeBinding typeCast = originalType.genericCast(targetType);
357
	    	setGenericCast(length, typeCast);
358
	        if (typeCast instanceof ReferenceBinding) {
359
				ReferenceBinding referenceCast = (ReferenceBinding) typeCast;
360
				if (!referenceCast.canBeSeenBy(scope)) {
361
		        	scope.problemReporter().invalidType(this, 
362
		        			new ProblemReferenceBinding(
363
								CharOperation.splitOn('.', referenceCast.shortReadableName()),
364
								referenceCast,
365
								ProblemReasons.NotVisible));
366
				}
367
	        }			    	
355
		} 	
368
		} 	
356
	}
369
	}
357
	super.computeConversion(scope, runtimeTimeType, compileTimeType);
370
	super.computeConversion(scope, runtimeTimeType, compileTimeType);

Return to bug 209153