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/GenericsRegressionTest.java (+134 lines)
Lines 379-382 Link Here
379
			"Incompatible operand types Class<X> and Class<I>\n" + 
379
			"Incompatible operand types Class<X> and Class<I>\n" + 
380
			"----------\n");
380
			"----------\n");
381
	}
381
	}
382
383
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=282152
384
public void test282152() {
385
    this.runConformTest(
386
        new String[] {
387
            "Test.java",
388
            "public interface Test<T extends Number> {\n" +
389
            "    public <U> void test(Test<? super U> t, U value);\n" +
390
            "    public void setValue(T v);" +
391
            "}",
392
            "Impl.java",
393
            "public class Impl<T extends Number> implements Test<T>{\n" +
394
            "    T val;" +
395
            "    public <U> void test(Test<? super U> t, U value) {\n" +
396
            "        t.setValue(value);\n" +
397
            "    }\n" +
398
            "    public void setValue(T v) {\n" +
399
            "        this.val = v;\n" +
400
            "    }\n" +
401
            "}",
402
            "Client.java",
403
            "public class Client {\n" +
404
            "    void test() {\n" +
405
            "        Impl<Integer> t1 = new Impl<Integer>();\n" +
406
            "        Double n = Double.valueOf(3.14);\n" +
407
            "        t1.test(new Impl<Number>(), n);\n" +
408
            "    }\n" +
409
            "}\n"
410
        },
411
        ""); // no specific success output string
412
}
413
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=282152
414
// violating lower bound
415
public void test282152b() {
416
    this.runNegativeTest(
417
        new String[] {
418
            "Test.java",
419
            "public interface Test<T extends Number> {\n" +
420
            "    public <U> void test(Test<? super U> t, U value);\n" +
421
            "    public void setValue(T v);" +
422
            "}",
423
            "Impl.java",
424
            "public class Impl<T extends Number> implements Test<T>{\n" +
425
            "    T val;" +
426
            "    public <U> void test(Test<? super U> t, U value) {\n" +
427
            "        t.setValue(value);\n" +
428
            "    }\n" +
429
            "    public void setValue(T v) {\n" +
430
            "        this.val = v;\n" +
431
            "    }\n" +
432
            "}",
433
            "Client.java",
434
            "public class Client {\n" +
435
            "    void test() {\n" +
436
            "        Impl<Integer> t1 = new Impl<Integer>();\n" +
437
            "        Number n = Double.valueOf(3.14);\n" +
438
            "        t1.test(new Impl<Double>(), n);\n" +
439
            "    }\n" +
440
            "}\n"
441
        },
442
        "----------\n" + 
443
		"1. ERROR in Client.java (at line 5)\n" + 
444
		"	t1.test(new Impl<Double>(), n);\n" + 
445
		"	   ^^^^\n" + 
446
		"The method test(Test<? super U>, U) in the type Impl<Integer> is not applicable for the arguments (Impl<Double>, Number)\n" + 
447
		"----------\n");
448
}
449
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=282152
450
// contradictory bounds
451
public void test282152c() {
452
    this.runNegativeTest(
453
        new String[] {
454
            "Test.java",
455
            "public interface Test<T extends Number> {\n" +
456
            "    public <U extends Exception> void test(Test<? super U> t, U value);\n" +
457
            "    public void setValue(T v);" +
458
            "}"
459
        },
460
        "----------\n" + 
461
		"1. ERROR in Test.java (at line 2)\n" + 
462
		"	public <U extends Exception> void test(Test<? super U> t, U value);\n" + 
463
		"	                                            ^^^^^^^^^\n" + 
464
		"Bound mismatch: The type ? super U is not a valid substitute for the bounded parameter <T extends Number> of the type Test<T>\n" + 
465
		"----------\n");
466
}
467
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=282152
468
// compatible constraints
469
public void test282152d() {
470
    this.runConformTest(
471
        new String[] {
472
            "Test.java",
473
            "public interface Test<T extends Number> {\n" +
474
            "    public <U extends Integer> void test(Test<? super U> t, U value);\n" +
475
            "    public void setValue(T v);" +
476
            "}",
477
            "Impl.java",
478
            "public class Impl<T extends Number> implements Test<T>{\n" +
479
            "    T val;" +
480
            "    public <U extends Integer> void test(Test<? super U> t, U value) {\n" +
481
            "        t.setValue(value);\n" +
482
            "    }\n" +
483
            "    public void setValue(T v) {\n" +
484
            "        this.val = v;\n" +
485
            "    }\n" +
486
            "}",
487
            "Client.java",
488
            "public class Client {\n" +
489
            "    void test() {\n" +
490
            "        Impl<Integer> t1 = new Impl<Integer>();\n" +
491
            "        Integer i = Integer.valueOf(3);\n" +
492
            "        t1.test(new Impl<Integer>(), i);\n" +
493
            "    }\n" +
494
            "}\n"
495
        },
496
        ""); // no specific success output string
497
}
498
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=282152
499
// direct use of type variable does not involve capture, thus no merging of constraints happens
500
public void test282152e() {
501
	this.runNegativeTest(
502
	    new String[] {
503
	        "Test.java",
504
	        "public interface Test<T extends Number> {\n" +
505
	        "    public <U> void test(Test<U> t, U value);\n" +
506
	        "    public void setValue(T v);" +
507
	        "}"
508
	    },
509
	    "----------\n" + 
510
		"1. ERROR in Test.java (at line 2)\n" + 
511
		"	public <U> void test(Test<U> t, U value);\n" + 
512
		"	                          ^\n" + 
513
		"Bound mismatch: The type U is not a valid substitute for the bounded parameter <T extends Number> of the type Test<T>\n" + 
514
		"----------\n");
515
}
382
}
516
}

Return to bug 282152