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 (+107 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<?>> {\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
			"	void test2(Comparable<?> v) {\n" +
49596
			"		if (v instanceof Integer) {\n" +
49597
			"			Object obj = Long.valueOf(((Integer) v).longValue());\n" +
49598
			"		}\n" +
49599
			"	}\n" +
49600
			"}",
49601
			"X2.java",
49602
			"class X2<T extends Comparable<? extends T>> {\n" +
49603
			"	public void test(T v) {\n" +
49604
			"		if (v instanceof Integer) {\n" +
49605
			"			Object obj = Long.valueOf(((Integer) v).longValue());\n" +
49606
			"		}\n" +
49607
			"	}\n" +
49608
			"	<U> void test2(Comparable<? extends U> v) {\n" +
49609
			"		if (v instanceof Integer) {\n" +
49610
			"			Object obj = Long.valueOf(((Integer) v).longValue());\n" +
49611
			"		}\n" +
49612
			"	}\n" +
49613
			"}",
49614
			"X3.java",
49615
			"class X3<T extends Comparable<? super T>> {\n" +
49616
			"	public void test(T v) {\n" +
49617
			"		if (v instanceof Integer) {\n" +
49618
			"			Object obj = Long.valueOf(((Integer) v).longValue());\n" +
49619
			"		}\n" +
49620
			"	}\n" +
49621
			"	<U> void test2(Comparable<? super U> v) {\n" +
49622
			"		if (v instanceof Integer) {\n" +
49623
			"			Object obj = Long.valueOf(((Integer) v).longValue());\n" +
49624
			"		}\n" +
49625
			"	}\n" +
49626
			"}",
49627
			"Y.java",
49628
			"class Y {\n" +
49629
			"	<U extends Number> void test(Comparable<? extends U> v) {\n" +
49630
			"		if (v instanceof Integer) {\n" +
49631
			"			Object obj = Long.valueOf(((Integer) v).longValue());\n" +
49632
			"		}\n" +
49633
			"	}\n" +
49634
			"}",
49635
		},
49636
		"----------\n" + 
49637
		"1. ERROR in X2.java (at line 3)\n" + 
49638
		"	if (v instanceof Integer) {\n" + 
49639
		"	    ^^^^^^^^^^^^^^^^^^^^\n" + 
49640
		"Incompatible conditional operand types T and Integer\n" + 
49641
		"----------\n" + 
49642
		"2. ERROR in X2.java (at line 4)\n" + 
49643
		"	Object obj = Long.valueOf(((Integer) v).longValue());\n" + 
49644
		"	                          ^^^^^^^^^^^^^\n" + 
49645
		"Cannot cast from T to Integer\n" + 
49646
		"----------\n" + 
49647
		"3. ERROR in X2.java (at line 8)\n" + 
49648
		"	if (v instanceof Integer) {\n" + 
49649
		"	    ^^^^^^^^^^^^^^^^^^^^\n" + 
49650
		"Incompatible conditional operand types Comparable<capture#1-of ? extends U> and Integer\n" + 
49651
		"----------\n" + 
49652
		"4. ERROR in X2.java (at line 9)\n" + 
49653
		"	Object obj = Long.valueOf(((Integer) v).longValue());\n" + 
49654
		"	                          ^^^^^^^^^^^^^\n" + 
49655
		"Cannot cast from Comparable<capture#2-of ? extends U> to Integer\n" + 
49656
		"----------\n" + 
49657
		"----------\n" + 
49658
		"1. ERROR in X3.java (at line 3)\n" + 
49659
		"	if (v instanceof Integer) {\n" + 
49660
		"	    ^^^^^^^^^^^^^^^^^^^^\n" + 
49661
		"Incompatible conditional operand types T and Integer\n" + 
49662
		"----------\n" + 
49663
		"2. ERROR in X3.java (at line 4)\n" + 
49664
		"	Object obj = Long.valueOf(((Integer) v).longValue());\n" + 
49665
		"	                          ^^^^^^^^^^^^^\n" + 
49666
		"Cannot cast from T to Integer\n" + 
49667
		"----------\n" + 
49668
		"3. ERROR in X3.java (at line 8)\n" + 
49669
		"	if (v instanceof Integer) {\n" + 
49670
		"	    ^^^^^^^^^^^^^^^^^^^^\n" + 
49671
		"Incompatible conditional operand types Comparable<capture#1-of ? super U> and Integer\n" + 
49672
		"----------\n" + 
49673
		"4. ERROR in X3.java (at line 9)\n" + 
49674
		"	Object obj = Long.valueOf(((Integer) v).longValue());\n" + 
49675
		"	                          ^^^^^^^^^^^^^\n" + 
49676
		"Cannot cast from Comparable<capture#2-of ? super U> to Integer\n" + 
49677
		"----------\n" + 
49678
		"----------\n" + 
49679
		"1. ERROR in Y.java (at line 3)\n" + 
49680
		"	if (v instanceof Integer) {\n" + 
49681
		"	    ^^^^^^^^^^^^^^^^^^^^\n" + 
49682
		"Incompatible conditional operand types Comparable<capture#1-of ? extends U> and Integer\n" + 
49683
		"----------\n" + 
49684
		"2. ERROR in Y.java (at line 4)\n" + 
49685
		"	Object obj = Long.valueOf(((Integer) v).longValue());\n" + 
49686
		"	                          ^^^^^^^^^^^^^\n" + 
49687
		"Cannot cast from Comparable<capture#2-of ? extends U> to Integer\n" + 
49688
		"----------\n"
49689
	);
49690
}
49584
}
49691
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java (-2 / +6 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
				// https://bugs.eclipse.org/bugs/show_bug.cgi?id=273787
584
				return !isCompatibleWith(otherType);
586
				return !isCompatibleWith(otherType);
585
			}
587
			}
586
		}
588
		}
Lines 823-829 Link Here
823
		}
825
		}
824
	} else {
826
	} else {
825
		if (lowerBound2 != null) {
827
		if (lowerBound2 != null) {
826
			if (lowerBound2.isTypeVariable() || isTypeVariable()) {
828
			if (isTypeVariable()) {
829
				// check compatibility when lowerBound2 is a type variable
830
				// https://bugs.eclipse.org/bugs/show_bug.cgi?id=273787
827
				return false;
831
				return false;
828
			}
832
			}
829
			return !lowerBound2.isCompatibleWith(this);
833
			return !lowerBound2.isCompatibleWith(this);

Return to bug 273787