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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/lookup/TypeVariableBinding.java (+3 lines)
Lines 114-119 Link Here
114
					break;
114
					break;
115
115
116
				case Wildcard.SUPER :
116
				case Wildcard.SUPER :
117
					// if the wildcard is lower-bounded by a type variable that has no relevant upper bound there's nothing to check here (bug 282152):
118
					if (wildcard.bound.isTypeVariable() && ((TypeVariableBinding)wildcard.bound).superclass.id == TypeIds.T_JavaLangObject)
119
						break;
117
					return boundCheck(substitution, wildcard.bound);
120
					return boundCheck(substitution, wildcard.bound);
118
121
119
				case Wildcard.UNBOUND :
122
				case Wildcard.UNBOUND :
(-)src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java (+133 lines)
Lines 50513-50516 Link Here
50513
		"Type mismatch: cannot convert from AnotherClass<capture#1-of ? extends IReferencedInterface> to AnotherClass<IReferencedInterface>\n" + 
50513
		"Type mismatch: cannot convert from AnotherClass<capture#1-of ? extends IReferencedInterface> to AnotherClass<IReferencedInterface>\n" + 
50514
		"----------\n");
50514
		"----------\n");
50515
}
50515
}
50516
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=282152
50517
public void test282152() {
50518
    this.runConformTest(
50519
        new String[] {
50520
            "Test.java",
50521
            "public interface Test<T extends Number> {\n" +
50522
            "    public <U> void test(Test<? super U> t, U value);\n" +
50523
            "    public void setValue(T v);" +
50524
            "}",
50525
            "Impl.java",
50526
            "public class Impl<T extends Number> implements Test<T>{\n" +
50527
            "    T val;" +
50528
            "    public <U> void test(Test<? super U> t, U value) {\n" +
50529
            "        t.setValue(value);\n" +
50530
            "    }\n" +
50531
            "    public void setValue(T v) {\n" +
50532
            "        this.val = v;\n" +
50533
            "    }\n" +
50534
            "}",
50535
            "Client.java",
50536
            "public class Client {\n" +
50537
            "    void test() {\n" +
50538
            "        Impl<Integer> t1 = new Impl<Integer>();\n" +
50539
            "        Double n = Double.valueOf(3.14);\n" +
50540
            "        t1.test(new Impl<Number>(), n);\n" +
50541
            "    }\n" +
50542
            "}\n"
50543
        },
50544
        ""); // no specific success output string
50545
}
50546
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=282152
50547
// violating lower bound
50548
public void test282152b() {
50549
    this.runNegativeTest(
50550
        new String[] {
50551
            "Test.java",
50552
            "public interface Test<T extends Number> {\n" +
50553
            "    public <U> void test(Test<? super U> t, U value);\n" +
50554
            "    public void setValue(T v);" +
50555
            "}",
50556
            "Impl.java",
50557
            "public class Impl<T extends Number> implements Test<T>{\n" +
50558
            "    T val;" +
50559
            "    public <U> void test(Test<? super U> t, U value) {\n" +
50560
            "        t.setValue(value);\n" +
50561
            "    }\n" +
50562
            "    public void setValue(T v) {\n" +
50563
            "        this.val = v;\n" +
50564
            "    }\n" +
50565
            "}",
50566
            "Client.java",
50567
            "public class Client {\n" +
50568
            "    void test() {\n" +
50569
            "        Impl<Integer> t1 = new Impl<Integer>();\n" +
50570
            "        Number n = Double.valueOf(3.14);\n" +
50571
            "        t1.test(new Impl<Double>(), n);\n" +
50572
            "    }\n" +
50573
            "}\n"
50574
        },
50575
        "----------\n" + 
50576
		"1. ERROR in Client.java (at line 5)\n" + 
50577
		"	t1.test(new Impl<Double>(), n);\n" + 
50578
		"	   ^^^^\n" + 
50579
		"The method test(Test<? super U>, U) in the type Impl<Integer> is not applicable for the arguments (Impl<Double>, Number)\n" + 
50580
		"----------\n");
50581
}
50582
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=282152
50583
// contradictory bounds
50584
public void test282152c() {
50585
    this.runNegativeTest(
50586
        new String[] {
50587
            "Test.java",
50588
            "public interface Test<T extends Number> {\n" +
50589
            "    public <U extends Exception> void test(Test<? super U> t, U value);\n" +
50590
            "    public void setValue(T v);" +
50591
            "}"
50592
        },
50593
        "----------\n" + 
50594
		"1. ERROR in Test.java (at line 2)\n" + 
50595
		"	public <U extends Exception> void test(Test<? super U> t, U value);\n" + 
50596
		"	                                            ^^^^^^^^^\n" + 
50597
		"Bound mismatch: The type ? super U is not a valid substitute for the bounded parameter <T extends Number> of the type Test<T>\n" + 
50598
		"----------\n");
50599
}
50600
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=282152
50601
// compatible constraints
50602
public void test282152d() {
50603
    this.runConformTest(
50604
        new String[] {
50605
            "Test.java",
50606
            "public interface Test<T extends Number> {\n" +
50607
            "    public <U extends Integer> void test(Test<? super U> t, U value);\n" +
50608
            "    public void setValue(T v);" +
50609
            "}",
50610
            "Impl.java",
50611
            "public class Impl<T extends Number> implements Test<T>{\n" +
50612
            "    T val;" +
50613
            "    public <U extends Integer> void test(Test<? super U> t, U value) {\n" +
50614
            "        t.setValue(value);\n" +
50615
            "    }\n" +
50616
            "    public void setValue(T v) {\n" +
50617
            "        this.val = v;\n" +
50618
            "    }\n" +
50619
            "}",
50620
            "Client.java",
50621
            "public class Client {\n" +
50622
            "    void test() {\n" +
50623
            "        Impl<Integer> t1 = new Impl<Integer>();\n" +
50624
            "        Integer i = Integer.valueOf(3);\n" +
50625
            "        t1.test(new Impl<Integer>(), i);\n" +
50626
            "    }\n" +
50627
            "}\n"
50628
        },
50629
        ""); // no specific success output string
50630
}
50631
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=282152
50632
// direct use of type variable does not involve capture, thus no merging of constraints happens
50633
public void test282152e() {
50634
	this.runNegativeTest(
50635
	    new String[] {
50636
	        "Test.java",
50637
	        "public interface Test<T extends Number> {\n" +
50638
	        "    public <U> void test(Test<U> t, U value);\n" +
50639
	        "    public void setValue(T v);" +
50640
	        "}"
50641
	    },
50642
	    "----------\n" + 
50643
		"1. ERROR in Test.java (at line 2)\n" + 
50644
		"	public <U> void test(Test<U> t, U value);\n" + 
50645
		"	                          ^\n" + 
50646
		"Bound mismatch: The type U is not a valid substitute for the bounded parameter <T extends Number> of the type Test<T>\n" + 
50647
		"----------\n");
50648
}
50516
}
50649
}

Return to bug 282152