Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 273787 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java (+41 lines)
Lines 49581-49584 Link Here
49581
		"----------\n"
49581
		"----------\n"
49582
	);
49582
	);
49583
}
49583
}
49584
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=273787
49585
public void test1453() {
49586
	this.runNegativeTest(
49587
		new String[] {
49588
			"X.java",
49589
			"class X<T extends Comparable<? extends T>> {\n" +
49590
			"	public void test(T v) {\n" +
49591
			"		if (v instanceof Integer) {\n" +
49592
			"			Object obj = Long.valueOf(((Integer) v).longValue());\n" +
49593
			"		}\n" +
49594
			"	}\n" +
49595
			"	<U> void test2(Comparable<? extends U> v) {\n" +
49596
			"		if (v instanceof Integer) {\n" +
49597
			"			Object obj = Long.valueOf(((Integer) v).longValue());\n" +
49598
			"		}\n" +
49599
			"	}\n" +
49600
			"}"
49601
		},
49602
		"----------\n" + 
49603
		"1. ERROR in X.java (at line 3)\n" + 
49604
		"	if (v instanceof Integer) {\n" + 
49605
		"	    ^^^^^^^^^^^^^^^^^^^^\n" + 
49606
		"Incompatible conditional operand types T and Integer\n" + 
49607
		"----------\n" + 
49608
		"2. ERROR in X.java (at line 4)\n" + 
49609
		"	Object obj = Long.valueOf(((Integer) v).longValue());\n" + 
49610
		"	                          ^^^^^^^^^^^^^\n" + 
49611
		"Cannot cast from T to Integer\n" + 
49612
		"----------\n" + 
49613
		"3. ERROR in X.java (at line 8)\n" + 
49614
		"	if (v instanceof Integer) {\n" + 
49615
		"	    ^^^^^^^^^^^^^^^^^^^^\n" + 
49616
		"Incompatible conditional operand types Comparable<capture#1-of ? extends U> and Integer\n" + 
49617
		"----------\n" + 
49618
		"4. ERROR in X.java (at line 9)\n" + 
49619
		"	Object obj = Long.valueOf(((Integer) v).longValue());\n" + 
49620
		"	                          ^^^^^^^^^^^^^\n" + 
49621
		"Cannot cast from Comparable<capture#2-of ? extends U> to Integer\n" + 
49622
		"----------\n"
49623
	);
49624
}
49584
}
49625
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java (-1 / +4 lines)
Lines 580-586 Link Here
580
				return !isCompatibleWith(otherType);
580
				return !isCompatibleWith(otherType);
581
			}
581
			}
582
		} else {
582
		} else {
583
			if (!isTypeVariable() && !otherType.isTypeVariable()) {
583
			if (!isTypeVariable()) {
584
				// check compatibility when otherType is a type variable
585
				// Comparable<? extends U> is then not compatible with Integer
586
				// https://bugs.eclipse.org/bugs/show_bug.cgi?id=273787
584
				return !isCompatibleWith(otherType);
587
				return !isCompatibleWith(otherType);
585
			}
588
			}
586
		}
589
		}

Return to bug 273787