View | Details | Raw Unified | Return to bug 240807
Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java (+70 lines)
Lines 47555-47558 Link Here
47555
		"Bound mismatch: The generic method bar() of type X<A> is not applicable for the arguments (). The inferred type Comparable<Comparable<B>> is not a valid substitute for the bounded parameter <B extends Comparable<B>>\n" + 
47555
		"Bound mismatch: The generic method bar() of type X<A> is not applicable for the arguments (). The inferred type Comparable<Comparable<B>> is not a valid substitute for the bounded parameter <B extends Comparable<B>>\n" + 
47556
		"----------\n");
47556
		"----------\n");
47557
}
47557
}
47558
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=240807
47559
public void test1405()  throws Exception {
47560
	this.runNegativeTest(
47561
		new String[] {
47562
			"X.java",
47563
			"import java.util.*;\n" + 
47564
			"public class X {\n" + 
47565
			"    X(List rawList, List<?> unboundList) {\n" + 
47566
			"            Throwable t0 = (Throwable) Collections.emptyList();\n" + 
47567
			"            Throwable t1 = (Throwable) rawList;\n" + 
47568
			"            Throwable t2 = (Throwable) unboundList;\n" + 
47569
			"           	Map m0 = (Map) Collections.emptyList();\n" + 
47570
			"            Map m1 = (Map) rawList;\n" + 
47571
			"            Map m2 = (Map) unboundList;\n" + 
47572
			"            Zork z;\n" + 
47573
			"    }\n" + 
47574
			"}\n",
47575
		},
47576
		"----------\n" + 
47577
		"1. WARNING in X.java (at line 3)\n" + 
47578
		"	X(List rawList, List<?> unboundList) {\n" + 
47579
		"	  ^^^^\n" + 
47580
		"List is a raw type. References to generic type List<E> should be parameterized\n" + 
47581
		"----------\n" + 
47582
		"2. WARNING in X.java (at line 4)\n" + 
47583
		"	Throwable t0 = (Throwable) Collections.emptyList();\n" + 
47584
		"	               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
47585
		"Type safety: Unchecked cast from List<Object> to Throwable\n" + 
47586
		"----------\n" + 
47587
		"3. WARNING in X.java (at line 6)\n" + 
47588
		"	Throwable t2 = (Throwable) unboundList;\n" + 
47589
		"	               ^^^^^^^^^^^^^^^^^^^^^^^\n" + 
47590
		"Type safety: Unchecked cast from List<capture#1-of ?> to Throwable\n" + 
47591
		"----------\n" + 
47592
		"4. WARNING in X.java (at line 7)\n" + 
47593
		"	Map m0 = (Map) Collections.emptyList();\n" + 
47594
		"	^^^\n" + 
47595
		"Map is a raw type. References to generic type Map<K,V> should be parameterized\n" + 
47596
		"----------\n" + 
47597
		"5. WARNING in X.java (at line 7)\n" + 
47598
		"	Map m0 = (Map) Collections.emptyList();\n" + 
47599
		"	          ^^^\n" + 
47600
		"Map is a raw type. References to generic type Map<K,V> should be parameterized\n" + 
47601
		"----------\n" + 
47602
		"6. WARNING in X.java (at line 8)\n" + 
47603
		"	Map m1 = (Map) rawList;\n" + 
47604
		"	^^^\n" + 
47605
		"Map is a raw type. References to generic type Map<K,V> should be parameterized\n" + 
47606
		"----------\n" + 
47607
		"7. WARNING in X.java (at line 8)\n" + 
47608
		"	Map m1 = (Map) rawList;\n" + 
47609
		"	          ^^^\n" + 
47610
		"Map is a raw type. References to generic type Map<K,V> should be parameterized\n" + 
47611
		"----------\n" + 
47612
		"8. WARNING in X.java (at line 9)\n" + 
47613
		"	Map m2 = (Map) unboundList;\n" + 
47614
		"	^^^\n" + 
47615
		"Map is a raw type. References to generic type Map<K,V> should be parameterized\n" + 
47616
		"----------\n" + 
47617
		"9. WARNING in X.java (at line 9)\n" + 
47618
		"	Map m2 = (Map) unboundList;\n" + 
47619
		"	          ^^^\n" + 
47620
		"Map is a raw type. References to generic type Map<K,V> should be parameterized\n" + 
47621
		"----------\n" + 
47622
		"10. ERROR in X.java (at line 10)\n" + 
47623
		"	Zork z;\n" + 
47624
		"	^^^^\n" + 
47625
		"Zork cannot be resolved to a type\n" + 
47626
		"----------\n");
47627
}
47558
}
47628
}
(-)compiler/org/eclipse/jdt/internal/compiler/ast/CastExpression.java (+6 lines)
Lines 386-391 Link Here
386
		case Binding.TYPE_PARAMETER :
386
		case Binding.TYPE_PARAMETER :
387
			this.bits |= ASTNode.UnsafeCast;
387
			this.bits |= ASTNode.UnsafeCast;
388
			return true;
388
			return true;
389
		case Binding.TYPE :
390
			if (isNarrowing && match == null && expressionType.isParameterizedType()) {
391
				this.bits |= ASTNode.UnsafeCast;
392
				return true;
393
			}
394
			break;
389
	}
395
	}
390
	if (!isNarrowing && match == this.resolvedType.leafComponentType()) { // do not tag as unnecessary when recursing through upper bounds
396
	if (!isNarrowing && match == this.resolvedType.leafComponentType()) { // do not tag as unnecessary when recursing through upper bounds
391
		tagAsUnnecessaryCast(scope, castType);
397
		tagAsUnnecessaryCast(scope, castType);

Return to bug 240807