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

Collapse All | Expand All

(-)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);
(-)src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java (+215 lines)
Lines 40642-40645 Link Here
40642
		true /* flush output directory */, 
40642
		true /* flush output directory */, 
40643
		customOptions);
40643
		customOptions);
40644
}
40644
}
40645
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=208873
40646
public void test1214() {
40647
	this.runConformTest(
40648
		new String[] {
40649
			"X.java",
40650
			"public class X {\n" + 
40651
			"	public interface Loader {\n" + 
40652
			"		public <T extends Integer, K extends String> T load(final K key);\n" + 
40653
			"	}\n" + 
40654
			"	Loader loader;\n" + 
40655
			"	public <K extends String, T extends Integer> T get(final K key) {\n" + 
40656
			"		T data = this.loader.load(key);\n" + 
40657
			"		return null;\n" + 
40658
			"	}\n" + 
40659
			"}\n", // =================
40660
		},
40661
		"");
40662
}
40663
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=208873 - variation
40664
public void test1215() {
40665
	this.runConformTest(
40666
		new String[] {
40667
			"X.java",
40668
			"public class X {\n" + 
40669
			"    <T, U extends T, V extends T> T cond1(boolean z, U x1, V x2) {\n" + 
40670
			"        return (z? x1: x2);\n" + 
40671
			"    }\n" + 
40672
			"}\n",
40673
		},
40674
		"");
40675
}	
40676
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209153
40677
public void test1216() {
40678
	this.runNegativeTest(
40679
		new String[] {
40680
			"X.java",
40681
			"public class X {\n" + 
40682
			"	public static void main(String[] args) {\n" + 
40683
			"		p.A myA = new p.A();\n" + 
40684
			"		myA.p = myA.box.get(); // [msgSend] generic cast to P -> error\n" + 
40685
			"		Object o = myA.box.get(); // ok, since no generic cast actually inserted\n" + 
40686
			"		myA.p = myA.getBox().t;// [fieldRef] generic cast to P -> error\n" + 
40687
			"		myA.p = myA.box.t;// [qName] generic cast to P -> error\n" + 
40688
			"		int pval = myA.box.t.pval;// intermediate access through P already flagged as error\n" + 
40689
			"	}\n" + 
40690
			"}\n",
40691
			"p/A.java",
40692
			"package p;\n" + 
40693
			"public class A {\n" + 
40694
			"	public static class Box<T> {\n" + 
40695
			"		public T t;\n" + 
40696
			"		public void set(T t) { this.t = t; }\n" + 
40697
			"		public T get()	{ return this.t; }\n" + 
40698
			"	}\n" + 
40699
			"	private class P {\n" + 
40700
			"		public int pval;\n" + 
40701
			"	}\n" + 
40702
			"	public P p;\n" + 
40703
			"	public Box<P> box;\n" + 
40704
			"	public Box<P> getBox() { return this.box; }\n" + 
40705
			"	public A next;\n" + 
40706
			"	public A getNext() { return this;} \n" + 
40707
			"	public A() {\n" + 
40708
			"		this.box = new Box<P>();\n" + 
40709
			"		this.box.set(new P());\n" + 
40710
			"	}\n" + 
40711
			"}\n"
40712
		},
40713
		"----------\n" + 
40714
		"1. ERROR in X.java (at line 4)\n" + 
40715
		"	myA.p = myA.box.get(); // [msgSend] generic cast to P -> error\n" + 
40716
		"	        ^^^^^^^^^^^^^\n" + 
40717
		"The type A.P is not visible\n" + 
40718
		"----------\n" + 
40719
		"2. ERROR in X.java (at line 6)\n" + 
40720
		"	myA.p = myA.getBox().t;// [fieldRef] generic cast to P -> error\n" + 
40721
		"	        ^^^^^^^^^^^^^^\n" + 
40722
		"The type A.P is not visible\n" + 
40723
		"----------\n" + 
40724
		"3. ERROR in X.java (at line 7)\n" + 
40725
		"	myA.p = myA.box.t;// [qName] generic cast to P -> error\n" + 
40726
		"	        ^^^\n" + 
40727
		"The type A.P is not visible\n" + 
40728
		"----------\n" + 
40729
		"4. ERROR in X.java (at line 8)\n" + 
40730
		"	int pval = myA.box.t.pval;// intermediate access through P already flagged as error\n" + 
40731
		"	           ^^^^^^^^^^^^^^\n" + 
40732
		"The type A.P is not visible\n" + 
40733
		"----------\n" + 
40734
		"----------\n" + 
40735
		"1. WARNING in p\\A.java (at line 18)\n" + 
40736
		"	this.box.set(new P());\n" + 
40737
		"	             ^^^^^^^\n" + 
40738
		"Access to enclosing constructor A.P() is emulated by a synthetic accessor method. Increasing its visibility will improve your performance\n" + 
40739
		"----------\n");
40740
}	
40741
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209153 - variation
40742
public void test1217() {
40743
	this.runNegativeTest(
40744
		new String[] {
40745
			"X.java",
40746
			"public class X {\n" + 
40747
			"	public static void main(String[] args) {\n" + 
40748
			"		p.A myA = new p.A();\n" + 
40749
			"		myA.p = myA.box.get(); // [msgSend] generic cast to P -> error\n" + 
40750
			"		Object o = myA.box.get(); // ok, since no generic cast actually inserted\n" + 
40751
			"		myA.p = myA.getBox().t;// [fieldRef] generic cast to P -> error\n" + 
40752
			"		myA.p = myA.box.t;// [qName] generic cast to P -> error\n" + 
40753
			"		int pval = myA.box.t.pval;// intermediate access through P already flagged as error\n" + 
40754
			"	}\n" + 
40755
			"}\n",
40756
			"p/A.java",
40757
			"package p;\n" + 
40758
			"public class A {\n" + 
40759
			"	public static class Box<T> {\n" + 
40760
			"		public T t;\n" + 
40761
			"		public void set(T t) { this.t = t; }\n" + 
40762
			"		public T get()	{ return this.t; }\n" + 
40763
			"	}\n" + 
40764
			"	protected class P {\n" + 
40765
			"		public int pval;\n" + 
40766
			"	}\n" + 
40767
			"	public P p;\n" + 
40768
			"	public Box<P> box;\n" + 
40769
			"	public Box<P> getBox() { return this.box; }\n" + 
40770
			"	public A next;\n" + 
40771
			"	public A getNext() { return this;} \n" + 
40772
			"	public A() {\n" + 
40773
			"		this.box = new Box<P>();\n" + 
40774
			"		this.box.set(new P());\n" + 
40775
			"	}\n" + 
40776
			"}\n"
40777
		},
40778
		"----------\n" + 
40779
		"1. ERROR in X.java (at line 4)\n" + 
40780
		"	myA.p = myA.box.get(); // [msgSend] generic cast to P -> error\n" + 
40781
		"	        ^^^^^^^^^^^^^\n" + 
40782
		"The type A.P is not visible\n" + 
40783
		"----------\n" + 
40784
		"2. ERROR in X.java (at line 6)\n" + 
40785
		"	myA.p = myA.getBox().t;// [fieldRef] generic cast to P -> error\n" + 
40786
		"	        ^^^^^^^^^^^^^^\n" + 
40787
		"The type A.P is not visible\n" + 
40788
		"----------\n" + 
40789
		"3. ERROR in X.java (at line 7)\n" + 
40790
		"	myA.p = myA.box.t;// [qName] generic cast to P -> error\n" + 
40791
		"	        ^^^\n" + 
40792
		"The type A.P is not visible\n" + 
40793
		"----------\n" + 
40794
		"4. ERROR in X.java (at line 8)\n" + 
40795
		"	int pval = myA.box.t.pval;// intermediate access through P already flagged as error\n" + 
40796
		"	           ^^^^^^^^^^^^^^\n" + 
40797
		"The type A.P is not visible\n" + 
40798
		"----------\n");
40799
}	
40800
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209153 - variation
40801
public void test1218() {
40802
	this.runNegativeTest(
40803
		new String[] {
40804
			"X.java",
40805
			"public class X {\n" + 
40806
			"	public static void main(String[] args) {\n" + 
40807
			"		p.A myA = new p.A();\n" + 
40808
			"		myA.p = myA.box.get(); // [msgSend] generic cast to P -> error\n" + 
40809
			"		Object o = myA.box.get(); // ok, since no generic cast actually inserted\n" + 
40810
			"		myA.p = myA.getBox().t;// [fieldRef] generic cast to P -> error\n" + 
40811
			"		myA.p = myA.box.t;// [qName] generic cast to P -> error\n" + 
40812
			"		int pval = myA.box.t.pval;// intermediate access through P already flagged as error\n" + 
40813
			"	}\n" + 
40814
			"}\n",
40815
			"p/A.java",
40816
			"package p;\n" + 
40817
			"public class A {\n" + 
40818
			"	public static class Box<T> {\n" + 
40819
			"		public T t;\n" + 
40820
			"		public void set(T t) { this.t = t; }\n" + 
40821
			"		public T get()	{ return this.t; }\n" + 
40822
			"	}\n" + 
40823
			"	class P {\n" + 
40824
			"		public int pval;\n" + 
40825
			"	}\n" + 
40826
			"	public P p;\n" + 
40827
			"	public Box<P> box;\n" + 
40828
			"	public Box<P> getBox() { return this.box; }\n" + 
40829
			"	public A next;\n" + 
40830
			"	public A getNext() { return this;} \n" + 
40831
			"	public A() {\n" + 
40832
			"		this.box = new Box<P>();\n" + 
40833
			"		this.box.set(new P());\n" + 
40834
			"	}\n" + 
40835
			"}\n"
40836
		},
40837
		"----------\n" + 
40838
		"1. ERROR in X.java (at line 4)\n" + 
40839
		"	myA.p = myA.box.get(); // [msgSend] generic cast to P -> error\n" + 
40840
		"	        ^^^^^^^^^^^^^\n" + 
40841
		"The type A.P is not visible\n" + 
40842
		"----------\n" + 
40843
		"2. ERROR in X.java (at line 6)\n" + 
40844
		"	myA.p = myA.getBox().t;// [fieldRef] generic cast to P -> error\n" + 
40845
		"	        ^^^^^^^^^^^^^^\n" + 
40846
		"The type A.P is not visible\n" + 
40847
		"----------\n" + 
40848
		"3. ERROR in X.java (at line 7)\n" + 
40849
		"	myA.p = myA.box.t;// [qName] generic cast to P -> error\n" + 
40850
		"	        ^^^\n" + 
40851
		"The type A.P is not visible\n" + 
40852
		"----------\n" + 
40853
		"4. ERROR in X.java (at line 8)\n" + 
40854
		"	int pval = myA.box.t.pval;// intermediate access through P already flagged as error\n" + 
40855
		"	           ^^^^^^^^^^^^^^\n" + 
40856
		"The type A.P is not visible\n" + 
40857
		"----------\n");
40858
}	
40859
40645
}
40860
}

Return to bug 209153