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

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java (-4 / +22 lines)
Lines 16878-16886 Link Here
16878
			},
16878
			},
16879
			"");
16879
			"");
16880
	}	
16880
	}	
16881
// results may change depending on 
16882
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=148046
16881
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=148046
16883
// **
16884
	public void test0550() {
16882
	public void test0550() {
16885
		this.runNegativeTest(
16883
		this.runNegativeTest(
16886
			new String[] {
16884
			new String[] {
Lines 16896-16905 Link Here
16896
				"}\n",
16894
				"}\n",
16897
			},
16895
			},
16898
			"----------\n" + 
16896
			"----------\n" + 
16899
			"1. WARNING in X.java (at line 6)\n" + 
16897
			"1. ERROR in X.java (at line 6)\n" + 
16900
			"	X<U> foo = (X<U>)param;\n" + 
16898
			"	X<U> foo = (X<U>)param;\n" + 
16901
			"	           ^^^^^^^^^^^\n" + 
16899
			"	           ^^^^^^^^^^^\n" + 
16902
			"Type safety: Unchecked cast from X<capture#1-of ? super A> to X<U>\n" + 
16900
			"Cannot cast from X<capture#1-of ? super A> to X<U>\n" + 
16903
			"----------\n" + 
16901
			"----------\n" + 
16904
			"2. ERROR in X.java (at line 8)\n" + 
16902
			"2. ERROR in X.java (at line 8)\n" + 
16905
			"	Zork z;\n" + 
16903
			"	Zork z;\n" + 
Lines 39814-39817 Link Here
39814
		"Unnecessary cast from List<Object> to ArrayList<? extends String>\n" + 
39812
		"Unnecessary cast from List<Object> to ArrayList<? extends String>\n" + 
39815
		"----------\n");
39813
		"----------\n");
39816
}
39814
}
39815
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148046 - variation
39816
public void test1193() {
39817
	this.runNegativeTest(
39818
		new String[] {
39819
			"X.java",
39820
			"class A {}\n" + 
39821
			"class B extends A {}\n" + 
39822
			"public class X<T> {\n" + 
39823
			"        public void foo(X<? super A> param) {\n" + 
39824
			"                X<B> bar = (X<B>) param; // unchecked warning vs error\n" + 
39825
			"        }\n" + 
39826
			"}\n", // =================
39827
		},
39828
		"----------\n" + 
39829
		"1. ERROR in X.java (at line 5)\n" + 
39830
		"	X<B> bar = (X<B>) param; // unchecked warning vs error\n" + 
39831
		"	           ^^^^^^^^^^^^\n" + 
39832
		"Cannot cast from X<capture#1-of ? super A> to X<B>\n" + 
39833
		"----------\n");
39834
}
39817
}
39835
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java (-11 / +19 lines)
Lines 626-637 Link Here
626
			break;
626
			break;
627
		case Binding.TYPE_PARAMETER :
627
		case Binding.TYPE_PARAMETER :
628
			final TypeVariableBinding variable = (TypeVariableBinding) this;
628
			final TypeVariableBinding variable = (TypeVariableBinding) this;
629
			if (variable.firstBound == null) // unbound variable
630
				return false;
631
			if (variable.isCapture()) {
629
			if (variable.isCapture()) {
632
				upperBound1 = variable.upperBound();
630
				CaptureBinding capture = (CaptureBinding) variable;
631
				lowerBound1 = capture.lowerBound;
632
				if (lowerBound1 == null) {
633
					if (capture.firstBound == null)
634
						return false;
635
					upperBound1 = capture.firstBound;
636
				}
633
				break;
637
				break;
634
			}
638
			}
639
			if (variable.firstBound == null) // unbound variable
640
				return false;
635
			TypeBinding eliminatedType = (paramType.environment.convertEliminatingTypeVariables(variable, paramType.genericType(), rank, null));
641
			TypeBinding eliminatedType = (paramType.environment.convertEliminatingTypeVariables(variable, paramType.genericType(), rank, null));
636
			switch (eliminatedType.kind()) {
642
			switch (eliminatedType.kind()) {
637
				case Binding.WILDCARD_TYPE :
643
				case Binding.WILDCARD_TYPE :
Lines 671-682 Link Here
671
			break;
677
			break;
672
		case Binding.TYPE_PARAMETER :
678
		case Binding.TYPE_PARAMETER :
673
			TypeVariableBinding otherVariable = (TypeVariableBinding) otherArgument;
679
			TypeVariableBinding otherVariable = (TypeVariableBinding) otherArgument;
674
			if (otherVariable.firstBound == null) // unbound variable
675
				return false;
676
			if (otherVariable.isCapture()) {
680
			if (otherVariable.isCapture()) {
677
				upperBound2 = otherVariable.upperBound(); // TODO need to improve for otherBounds
681
				CaptureBinding otherCapture = (CaptureBinding) otherVariable;
682
				lowerBound2 = otherCapture.lowerBound;
683
				if (lowerBound2 == null) {
684
					if (otherCapture.firstBound == null)
685
						return false;
686
					upperBound2 = otherCapture.firstBound;
687
				}
678
				break;
688
				break;
679
			} 
689
			}
690
			if (otherVariable.firstBound == null) // unbound variable
691
				return false;
680
			TypeBinding otherEliminatedType = (paramType.environment.convertEliminatingTypeVariables(otherVariable, paramType.genericType(), rank, null));
692
			TypeBinding otherEliminatedType = (paramType.environment.convertEliminatingTypeVariables(otherVariable, paramType.genericType(), rank, null));
681
			switch (otherEliminatedType.kind()) {
693
			switch (otherEliminatedType.kind()) {
682
				case Binding.WILDCARD_TYPE :
694
				case Binding.WILDCARD_TYPE :
Lines 701-715 Link Here
701
713
702
		} else if (upperBound2 != null) {
714
		} else if (upperBound2 != null) {
703
			return !lowerBound1.isCompatibleWith(upperBound2);
715
			return !lowerBound1.isCompatibleWith(upperBound2);
704
//			return lowerBound1.isProvableDistinctSubType(upperBound2);
705
		} else {
716
		} else {
706
			return !lowerBound1.isCompatibleWith(otherArgument);
717
			return !lowerBound1.isCompatibleWith(otherArgument);
707
//			return lowerBound1.isProvableDistinctSubType(otherArgument);
708
		}
718
		}
709
	} else if (upperBound1 != null) {
719
	} else if (upperBound1 != null) {
710
		if (lowerBound2 != null) {
720
		if (lowerBound2 != null) {
711
			return !lowerBound2.isCompatibleWith(upperBound1);
721
			return !lowerBound2.isCompatibleWith(upperBound1);
712
			//return lowerBound2.isProvableDistinctSubType(upperBound1);
713
		} else if (upperBound2 != null) {
722
		} else if (upperBound2 != null) {
714
			return upperBound1.isProvableDistinctSubType(upperBound2) 
723
			return upperBound1.isProvableDistinctSubType(upperBound2) 
715
							&& upperBound2.isProvableDistinctSubType(upperBound1);
724
							&& upperBound2.isProvableDistinctSubType(upperBound1);
Lines 719-725 Link Here
719
	} else {
728
	} else {
720
		if (lowerBound2 != null) {
729
		if (lowerBound2 != null) {
721
			return !lowerBound2.isCompatibleWith(this);
730
			return !lowerBound2.isCompatibleWith(this);
722
//			return lowerBound2.isProvableDistinctSubType(this);
723
		} else if (upperBound2 != null) {
731
		} else if (upperBound2 != null) {
724
			return this.isProvableDistinctSubType(upperBound2);
732
			return this.isProvableDistinctSubType(upperBound2);
725
		} else {
733
		} else {

Return to bug 148046