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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java (-2 / +5 lines)
Lines 360-367 Link Here
360
						} else {
360
						} else {
361
							codeStream.invokestatic(syntheticAccessors[READ]);
361
							codeStream.invokestatic(syntheticAccessors[READ]);
362
						}
362
						}
363
						// required cast must occur even if no value is required
364
						if (this.genericCast != null) codeStream.checkcast(this.genericCast);
363
						if (valueRequired) {
365
						if (valueRequired) {
364
							if (this.genericCast != null) codeStream.checkcast(this.genericCast);
365
							codeStream.generateImplicitConversion(implicitConversion);
366
							codeStream.generateImplicitConversion(implicitConversion);
366
						} else {
367
						} else {
367
							if ((implicitConversion & TypeIds.UNBOXING) != 0) {
368
							if ((implicitConversion & TypeIds.UNBOXING) != 0) {
Lines 378-384 Link Here
378
							}
379
							}
379
						}							
380
						}							
380
					} else {
381
					} else {
381
						if (!valueRequired && ((implicitConversion & TypeIds.UNBOXING) == 0)) {
382
						if (!valueRequired 
383
								&& ((implicitConversion & TypeIds.UNBOXING) == 0) 
384
								&& this.genericCast == null) { // required cast must occur even if no value is required
382
							// if no valueRequired, optimize out entire gen
385
							// if no valueRequired, optimize out entire gen
383
							break;
386
							break;
384
						}
387
						}
(-)compiler/org/eclipse/jdt/internal/compiler/ast/FieldReference.java (-2 / +4 lines)
Lines 189-195 Link Here
189
		return;
189
		return;
190
	}
190
	}
191
	if (valueRequired || (!isThisReceiver && currentScope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4)
191
	if (valueRequired || (!isThisReceiver && currentScope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4)
192
			|| ((implicitConversion & TypeIds.UNBOXING) != 0)) {
192
			|| ((implicitConversion & TypeIds.UNBOXING) != 0)
193
			|| (this.genericCast != null)) {
193
		receiver.generateCode(currentScope, codeStream, !isStatic);
194
		receiver.generateCode(currentScope, codeStream, !isStatic);
194
		pc = codeStream.position;
195
		pc = codeStream.position;
195
		if (this.codegenBinding.declaringClass == null) { // array length
196
		if (this.codegenBinding.declaringClass == null) { // array length
Lines 210-217 Link Here
210
			} else {
211
			} else {
211
				codeStream.invokestatic(syntheticAccessors[READ]);
212
				codeStream.invokestatic(syntheticAccessors[READ]);
212
			}
213
			}
214
			// required cast must occur even if no value is required
215
			if (this.genericCast != null) codeStream.checkcast(this.genericCast);
213
			if (valueRequired) {
216
			if (valueRequired) {
214
				if (this.genericCast != null) codeStream.checkcast(this.genericCast);
215
				codeStream.generateImplicitConversion(implicitConversion);
217
				codeStream.generateImplicitConversion(implicitConversion);
216
			} else {
218
			} else {
217
				if ((implicitConversion & TypeIds.UNBOXING) != 0) {
219
				if ((implicitConversion & TypeIds.UNBOXING) != 0) {
(-)compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java (-3 / +3 lines)
Lines 144-154 Link Here
144
	} else {
144
	} else {
145
		codeStream.invokestatic(syntheticAccessor);
145
		codeStream.invokestatic(syntheticAccessor);
146
	}
146
	}
147
	// operation on the returned value
147
	// required cast must occur even if no value is required
148
	if (this.valueCast != null) codeStream.checkcast(this.valueCast);
149
148
	if (valueRequired){
150
	if (valueRequired){
149
		// implicit conversion if necessary
151
		// implicit conversion if necessary
150
		if (this.valueCast != null) 
151
			codeStream.checkcast(this.valueCast);
152
		codeStream.generateImplicitConversion(implicitConversion);
152
		codeStream.generateImplicitConversion(implicitConversion);
153
	} else {
153
	} else {
154
		// pop return value if any
154
		// pop return value if any
(-)src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java (+136 lines)
Lines 36736-36739 Link Here
36736
		},
36736
		},
36737
		"");		
36737
		"");		
36738
}
36738
}
36739
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177194
36740
public void testONLY_1109() {
36741
	Map settings = getCompilerOptions();
36742
	settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT);
36743
	this.runConformTest(
36744
		new String[] {
36745
			"X.java",
36746
			"class A<T> {\n" + 
36747
			"        public T foo(Object o) {\n" + 
36748
			"                return (T) o; // should get unchecked warning\n" + 
36749
			"        }\n" + 
36750
			"}\n" + 
36751
			"\n" + 
36752
			"public class X {\n" + 
36753
			"        public static void main(String[] args) {\n" + 
36754
			"                A<X> a = new A<X>();\n" + 
36755
			"                try {\n" + 
36756
			"	                X s = a.foo(new Object());\n" + 
36757
			"                } catch(ClassCastException e) {\n" + 
36758
			"                	System.out.println(\"SUCCESS\");\n" + 
36759
			"                	return;\n" + 
36760
			"                }\n" + 
36761
			"            	System.out.println(\"FAILED\");\n" + 
36762
			"        }\n" + 
36763
			"}\n", // =================
36764
		},
36765
		"SUCCESS",
36766
		null,
36767
		true,
36768
		null,
36769
		settings,
36770
		null);		
36771
}
36772
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177194 - variation
36773
public void testONLY_1110() {
36774
	Map settings = getCompilerOptions();
36775
	settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT);
36776
	this.runConformTest(
36777
		new String[] {
36778
			"X.java",
36779
			"class A<T> {\n" + 
36780
			"        public T foo;\n" +
36781
			"}\n" + 
36782
			"\n" + 
36783
			"public class X {\n" + 
36784
			"        public static void main(String[] args) {\n" + 
36785
			"                A<X> a = new A<X>();\n" + 
36786
			"				 A ua = a;\n" +
36787
			"				 ua.foo = new Object();\n" +
36788
			"                try {\n" + 
36789
			"	                X s = a.foo;\n" + 
36790
			"                } catch(ClassCastException e) {\n" + 
36791
			"                	System.out.println(\"SUCCESS\");\n" + 
36792
			"                	return;\n" + 
36793
			"                }\n" + 
36794
			"            	System.out.println(\"FAILED\");\n" + 
36795
			"        }\n" + 
36796
			"}\n", // =================
36797
		},
36798
		"SUCCESS",
36799
		null,
36800
		true,
36801
		null,
36802
		settings,
36803
		null);		
36804
}
36805
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177194 - variation
36806
public void testONLY_1111() {
36807
	Map settings = getCompilerOptions();
36808
	settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT);
36809
	this.runConformTest(
36810
		new String[] {
36811
			"X.java",
36812
			"class A<T> {\n" + 
36813
			"        public T foo;\n" +
36814
			"}\n" + 
36815
			"\n" + 
36816
			"public class X extends A<X>{\n" + 
36817
			"        public static void main(String[] args) {\n" + 
36818
			"			new X().foo();\n" +
36819
			"		 }\n" +
36820
			" 		 public void foo() {\n" +
36821
			"				 A ua = this;\n" +
36822
			"				 ua.foo = new Object();\n" +
36823
			"                try {\n" + 
36824
			"	                X s = foo;\n" + 
36825
			"                } catch(ClassCastException e) {\n" + 
36826
			"                	System.out.println(\"SUCCESS\");\n" + 
36827
			"                	return;\n" + 
36828
			"                }\n" + 
36829
			"            	System.out.println(\"FAILED\");\n" + 
36830
			"        }\n" + 
36831
			"}\n", // =================
36832
		},
36833
		"SUCCESS",
36834
		null,
36835
		true,
36836
		null,
36837
		settings,
36838
		null);		
36839
}
36840
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177194 - variation
36841
public void testONLY_1112() {
36842
	Map settings = getCompilerOptions();
36843
	settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT);
36844
	this.runConformTest(
36845
		new String[] {
36846
			"X.java",
36847
			"class A<T> {\n" + 
36848
			"        public T foo;\n" +
36849
			"}\n" + 
36850
			"\n" + 
36851
			"public class X extends A<X>{\n" + 
36852
			"        public static void main(String[] args) {\n" + 
36853
			"			new X().foo();\n" +
36854
			"		 }\n" +
36855
			" 		 public void foo() {\n" +
36856
			"				 A ua = this;\n" +
36857
			"				 ua.foo = new Object();\n" +
36858
			"                try {\n" + 
36859
			"	                X s = this.foo;\n" + 
36860
			"                } catch(ClassCastException e) {\n" + 
36861
			"                	System.out.println(\"SUCCESS\");\n" + 
36862
			"                	return;\n" + 
36863
			"                }\n" + 
36864
			"            	System.out.println(\"FAILED\");\n" + 
36865
			"        }\n" + 
36866
			"}\n", // =================
36867
		},
36868
		"SUCCESS",
36869
		null,
36870
		true,
36871
		null,
36872
		settings,
36873
		null);		
36874
}
36739
}
36875
}

Return to bug 177194