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 (+214 lines)
Lines 38884-38888 Link Here
38884
		"Bound mismatch: The generic method throwE(Object...) of type X is not applicable for the arguments (Object[]). The inferred type Object[] is not a valid substitute for the bounded parameter <E extends Exception>\n" + 
38884
		"Bound mismatch: The generic method throwE(Object...) of type X is not applicable for the arguments (Object[]). The inferred type Object[] is not a valid substitute for the bounded parameter <E extends Exception>\n" + 
38885
		"----------\n");
38885
		"----------\n");
38886
}
38886
}
38887
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=208873
38888
public void test1212() {
38889
	this.runConformTest(
38890
		new String[] {
38891
			"X.java",
38892
			"public class X {\n" + 
38893
			"	public interface Loader {\n" + 
38894
			"		public <T extends Integer, K extends String> T load(final K key);\n" + 
38895
			"	}\n" + 
38896
			"	Loader loader;\n" + 
38897
			"	public <K extends String, T extends Integer> T get(final K key) {\n" + 
38898
			"		T data = this.loader.load(key);\n" + 
38899
			"		return null;\n" + 
38900
			"	}\n" + 
38901
			"}\n", // =================
38902
		},
38903
		"");
38904
}
38905
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=208873 - variation
38906
public void test1213() {
38907
	this.runConformTest(
38908
		new String[] {
38909
			"X.java",
38910
			"public class X {\n" + 
38911
			"    <T, U extends T, V extends T> T cond1(boolean z, U x1, V x2) {\n" + 
38912
			"        return (z? x1: x2);\n" + 
38913
			"    }\n" + 
38914
			"}\n",
38915
		},
38916
		"");
38917
}	
38918
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209153
38919
public void test1214() {
38920
	this.runNegativeTest(
38921
		new String[] {
38922
			"X.java",
38923
			"public class X {\n" + 
38924
			"	public static void main(String[] args) {\n" + 
38925
			"		p.A myA = new p.A();\n" + 
38926
			"		myA.p = myA.box.get(); // [msgSend] generic cast to P -> error\n" + 
38927
			"		Object o = myA.box.get(); // ok, since no generic cast actually inserted\n" + 
38928
			"		myA.p = myA.getBox().t;// [fieldRef] generic cast to P -> error\n" + 
38929
			"		myA.p = myA.box.t;// [qName] generic cast to P -> error\n" + 
38930
			"		int pval = myA.box.t.pval;// intermediate access through P already flagged as error\n" + 
38931
			"	}\n" + 
38932
			"}\n",
38933
			"p/A.java",
38934
			"package p;\n" + 
38935
			"public class A {\n" + 
38936
			"	public static class Box<T> {\n" + 
38937
			"		public T t;\n" + 
38938
			"		public void set(T t) { this.t = t; }\n" + 
38939
			"		public T get()	{ return this.t; }\n" + 
38940
			"	}\n" + 
38941
			"	private class P {\n" + 
38942
			"		public int pval;\n" + 
38943
			"	}\n" + 
38944
			"	public P p;\n" + 
38945
			"	public Box<P> box;\n" + 
38946
			"	public Box<P> getBox() { return this.box; }\n" + 
38947
			"	public A next;\n" + 
38948
			"	public A getNext() { return this;} \n" + 
38949
			"	public A() {\n" + 
38950
			"		this.box = new Box<P>();\n" + 
38951
			"		this.box.set(new P());\n" + 
38952
			"	}\n" + 
38953
			"}\n"
38954
		},
38955
		"----------\n" + 
38956
		"1. ERROR in X.java (at line 4)\n" + 
38957
		"	myA.p = myA.box.get(); // [msgSend] generic cast to P -> error\n" + 
38958
		"	        ^^^^^^^^^^^^^\n" + 
38959
		"The type A.P is not visible\n" + 
38960
		"----------\n" + 
38961
		"2. ERROR in X.java (at line 6)\n" + 
38962
		"	myA.p = myA.getBox().t;// [fieldRef] generic cast to P -> error\n" + 
38963
		"	        ^^^^^^^^^^^^^^\n" + 
38964
		"The type A.P is not visible\n" + 
38965
		"----------\n" + 
38966
		"3. ERROR in X.java (at line 7)\n" + 
38967
		"	myA.p = myA.box.t;// [qName] generic cast to P -> error\n" + 
38968
		"	        ^^^\n" + 
38969
		"The type A.P is not visible\n" + 
38970
		"----------\n" + 
38971
		"4. ERROR in X.java (at line 8)\n" + 
38972
		"	int pval = myA.box.t.pval;// intermediate access through P already flagged as error\n" + 
38973
		"	           ^^^^^^^^^^^^^^\n" + 
38974
		"The type A.P is not visible\n" + 
38975
		"----------\n" + 
38976
		"----------\n" + 
38977
		"1. WARNING in p\\A.java (at line 18)\n" + 
38978
		"	this.box.set(new P());\n" + 
38979
		"	             ^^^^^^^\n" + 
38980
		"Access to enclosing constructor A.P() is emulated by a synthetic accessor method. Increasing its visibility will improve your performance\n" + 
38981
		"----------\n");
38982
}	
38983
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209153 - variation
38984
public void test1215() {
38985
	this.runNegativeTest(
38986
		new String[] {
38987
			"X.java",
38988
			"public class X {\n" + 
38989
			"	public static void main(String[] args) {\n" + 
38990
			"		p.A myA = new p.A();\n" + 
38991
			"		myA.p = myA.box.get(); // [msgSend] generic cast to P -> error\n" + 
38992
			"		Object o = myA.box.get(); // ok, since no generic cast actually inserted\n" + 
38993
			"		myA.p = myA.getBox().t;// [fieldRef] generic cast to P -> error\n" + 
38994
			"		myA.p = myA.box.t;// [qName] generic cast to P -> error\n" + 
38995
			"		int pval = myA.box.t.pval;// intermediate access through P already flagged as error\n" + 
38996
			"	}\n" + 
38997
			"}\n",
38998
			"p/A.java",
38999
			"package p;\n" + 
39000
			"public class A {\n" + 
39001
			"	public static class Box<T> {\n" + 
39002
			"		public T t;\n" + 
39003
			"		public void set(T t) { this.t = t; }\n" + 
39004
			"		public T get()	{ return this.t; }\n" + 
39005
			"	}\n" + 
39006
			"	protected class P {\n" + 
39007
			"		public int pval;\n" + 
39008
			"	}\n" + 
39009
			"	public P p;\n" + 
39010
			"	public Box<P> box;\n" + 
39011
			"	public Box<P> getBox() { return this.box; }\n" + 
39012
			"	public A next;\n" + 
39013
			"	public A getNext() { return this;} \n" + 
39014
			"	public A() {\n" + 
39015
			"		this.box = new Box<P>();\n" + 
39016
			"		this.box.set(new P());\n" + 
39017
			"	}\n" + 
39018
			"}\n"
39019
		},
39020
		"----------\n" + 
39021
		"1. ERROR in X.java (at line 4)\n" + 
39022
		"	myA.p = myA.box.get(); // [msgSend] generic cast to P -> error\n" + 
39023
		"	        ^^^^^^^^^^^^^\n" + 
39024
		"The type A.P is not visible\n" + 
39025
		"----------\n" + 
39026
		"2. ERROR in X.java (at line 6)\n" + 
39027
		"	myA.p = myA.getBox().t;// [fieldRef] generic cast to P -> error\n" + 
39028
		"	        ^^^^^^^^^^^^^^\n" + 
39029
		"The type A.P is not visible\n" + 
39030
		"----------\n" + 
39031
		"3. ERROR in X.java (at line 7)\n" + 
39032
		"	myA.p = myA.box.t;// [qName] generic cast to P -> error\n" + 
39033
		"	        ^^^\n" + 
39034
		"The type A.P is not visible\n" + 
39035
		"----------\n" + 
39036
		"4. ERROR in X.java (at line 8)\n" + 
39037
		"	int pval = myA.box.t.pval;// intermediate access through P already flagged as error\n" + 
39038
		"	           ^^^^^^^^^^^^^^\n" + 
39039
		"The type A.P is not visible\n" + 
39040
		"----------\n");
39041
}	
39042
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209153 - variation
39043
public void test1216() {
39044
	this.runNegativeTest(
39045
		new String[] {
39046
			"X.java",
39047
			"public class X {\n" + 
39048
			"	public static void main(String[] args) {\n" + 
39049
			"		p.A myA = new p.A();\n" + 
39050
			"		myA.p = myA.box.get(); // [msgSend] generic cast to P -> error\n" + 
39051
			"		Object o = myA.box.get(); // ok, since no generic cast actually inserted\n" + 
39052
			"		myA.p = myA.getBox().t;// [fieldRef] generic cast to P -> error\n" + 
39053
			"		myA.p = myA.box.t;// [qName] generic cast to P -> error\n" + 
39054
			"		int pval = myA.box.t.pval;// intermediate access through P already flagged as error\n" + 
39055
			"	}\n" + 
39056
			"}\n",
39057
			"p/A.java",
39058
			"package p;\n" + 
39059
			"public class A {\n" + 
39060
			"	public static class Box<T> {\n" + 
39061
			"		public T t;\n" + 
39062
			"		public void set(T t) { this.t = t; }\n" + 
39063
			"		public T get()	{ return this.t; }\n" + 
39064
			"	}\n" + 
39065
			"	class P {\n" + 
39066
			"		public int pval;\n" + 
39067
			"	}\n" + 
39068
			"	public P p;\n" + 
39069
			"	public Box<P> box;\n" + 
39070
			"	public Box<P> getBox() { return this.box; }\n" + 
39071
			"	public A next;\n" + 
39072
			"	public A getNext() { return this;} \n" + 
39073
			"	public A() {\n" + 
39074
			"		this.box = new Box<P>();\n" + 
39075
			"		this.box.set(new P());\n" + 
39076
			"	}\n" + 
39077
			"}\n"
39078
		},
39079
		"----------\n" + 
39080
		"1. ERROR in X.java (at line 4)\n" + 
39081
		"	myA.p = myA.box.get(); // [msgSend] generic cast to P -> error\n" + 
39082
		"	        ^^^^^^^^^^^^^\n" + 
39083
		"The type A.P is not visible\n" + 
39084
		"----------\n" + 
39085
		"2. ERROR in X.java (at line 6)\n" + 
39086
		"	myA.p = myA.getBox().t;// [fieldRef] generic cast to P -> error\n" + 
39087
		"	        ^^^^^^^^^^^^^^\n" + 
39088
		"The type A.P is not visible\n" + 
39089
		"----------\n" + 
39090
		"3. ERROR in X.java (at line 7)\n" + 
39091
		"	myA.p = myA.box.t;// [qName] generic cast to P -> error\n" + 
39092
		"	        ^^^\n" + 
39093
		"The type A.P is not visible\n" + 
39094
		"----------\n" + 
39095
		"4. ERROR in X.java (at line 8)\n" + 
39096
		"	int pval = myA.box.t.pval;// intermediate access through P already flagged as error\n" + 
39097
		"	           ^^^^^^^^^^^^^^\n" + 
39098
		"The type A.P is not visible\n" + 
39099
		"----------\n");
39100
}	
38887
39101
38888
}
39102
}

Return to bug 209153