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 (-1 / +5 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bug 282152 - [1.5][compiler] Generics code rejected by Eclipse but accepted by javac
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.lookup;
12
package org.eclipse.jdt.internal.compiler.lookup;
12
13
Lines 114-119 Link Here
114
					break;
115
					break;
115
116
116
				case Wildcard.SUPER :
117
				case Wildcard.SUPER :
118
					// if the wildcard is lower-bounded by a type variable that has no relevant upper bound there's nothing to check here (bug 282152):
119
					if (wildcard.bound.isTypeVariable() && ((TypeVariableBinding)wildcard.bound).superclass.id == TypeIds.T_JavaLangObject)
120
						break;
117
					return boundCheck(substitution, wildcard.bound);
121
					return boundCheck(substitution, wildcard.bound);
118
122
119
				case Wildcard.UNBOUND :
123
				case Wildcard.UNBOUND :
(-)src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java (+135 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bug 282152 - [1.5][compiler] Generics code rejected by Eclipse but accepted by javac
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.core.tests.compiler.regression;
12
package org.eclipse.jdt.core.tests.compiler.regression;
12
13
Lines 379-382 Link Here
379
			"Incompatible operand types Class<X> and Class<I>\n" + 
380
			"Incompatible operand types Class<X> and Class<I>\n" + 
380
			"----------\n");
381
			"----------\n");
381
	}
382
	}
383
384
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=282152
385
public void test282152() {
386
    this.runConformTest(
387
        new String[] {
388
            "Test.java",
389
            "public interface Test<T extends Number> {\n" +
390
            "    public <U> void test(Test<? super U> t, U value);\n" +
391
            "    public void setValue(T v);" +
392
            "}",
393
            "Impl.java",
394
            "public class Impl<T extends Number> implements Test<T>{\n" +
395
            "    T val;" +
396
            "    public <U> void test(Test<? super U> t, U value) {\n" +
397
            "        t.setValue(value);\n" +
398
            "    }\n" +
399
            "    public void setValue(T v) {\n" +
400
            "        this.val = v;\n" +
401
            "    }\n" +
402
            "}",
403
            "Client.java",
404
            "public class Client {\n" +
405
            "    void test() {\n" +
406
            "        Impl<Integer> t1 = new Impl<Integer>();\n" +
407
            "        Double n = Double.valueOf(3.14);\n" +
408
            "        t1.test(new Impl<Number>(), n);\n" +
409
            "    }\n" +
410
            "}\n"
411
        },
412
        ""); // no specific success output string
413
}
414
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=282152
415
// violating lower bound
416
public void test282152b() {
417
    this.runNegativeTest(
418
        new String[] {
419
            "Test.java",
420
            "public interface Test<T extends Number> {\n" +
421
            "    public <U> void test(Test<? super U> t, U value);\n" +
422
            "    public void setValue(T v);" +
423
            "}",
424
            "Impl.java",
425
            "public class Impl<T extends Number> implements Test<T>{\n" +
426
            "    T val;" +
427
            "    public <U> void test(Test<? super U> t, U value) {\n" +
428
            "        t.setValue(value);\n" +
429
            "    }\n" +
430
            "    public void setValue(T v) {\n" +
431
            "        this.val = v;\n" +
432
            "    }\n" +
433
            "}",
434
            "Client.java",
435
            "public class Client {\n" +
436
            "    void test() {\n" +
437
            "        Impl<Integer> t1 = new Impl<Integer>();\n" +
438
            "        Number n = Double.valueOf(3.14);\n" +
439
            "        t1.test(new Impl<Double>(), n);\n" +
440
            "    }\n" +
441
            "}\n"
442
        },
443
        "----------\n" + 
444
		"1. ERROR in Client.java (at line 5)\n" + 
445
		"	t1.test(new Impl<Double>(), n);\n" + 
446
		"	   ^^^^\n" + 
447
		"The method test(Test<? super U>, U) in the type Impl<Integer> is not applicable for the arguments (Impl<Double>, Number)\n" + 
448
		"----------\n");
449
}
450
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=282152
451
// contradictory bounds
452
public void test282152c() {
453
    this.runNegativeTest(
454
        new String[] {
455
            "Test.java",
456
            "public interface Test<T extends Number> {\n" +
457
            "    public <U extends Exception> void test(Test<? super U> t, U value);\n" +
458
            "    public void setValue(T v);" +
459
            "}"
460
        },
461
        "----------\n" + 
462
		"1. ERROR in Test.java (at line 2)\n" + 
463
		"	public <U extends Exception> void test(Test<? super U> t, U value);\n" + 
464
		"	                                            ^^^^^^^^^\n" + 
465
		"Bound mismatch: The type ? super U is not a valid substitute for the bounded parameter <T extends Number> of the type Test<T>\n" + 
466
		"----------\n");
467
}
468
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=282152
469
// compatible constraints
470
public void test282152d() {
471
    this.runConformTest(
472
        new String[] {
473
            "Test.java",
474
            "public interface Test<T extends Number> {\n" +
475
            "    public <U extends Integer> void test(Test<? super U> t, U value);\n" +
476
            "    public void setValue(T v);" +
477
            "}",
478
            "Impl.java",
479
            "public class Impl<T extends Number> implements Test<T>{\n" +
480
            "    T val;" +
481
            "    public <U extends Integer> void test(Test<? super U> t, U value) {\n" +
482
            "        t.setValue(value);\n" +
483
            "    }\n" +
484
            "    public void setValue(T v) {\n" +
485
            "        this.val = v;\n" +
486
            "    }\n" +
487
            "}",
488
            "Client.java",
489
            "public class Client {\n" +
490
            "    void test() {\n" +
491
            "        Impl<Integer> t1 = new Impl<Integer>();\n" +
492
            "        Integer i = Integer.valueOf(3);\n" +
493
            "        t1.test(new Impl<Integer>(), i);\n" +
494
            "    }\n" +
495
            "}\n"
496
        },
497
        ""); // no specific success output string
498
}
499
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=282152
500
// direct use of type variable does not involve capture, thus no merging of constraints happens
501
public void test282152e() {
502
	this.runNegativeTest(
503
	    new String[] {
504
	        "Test.java",
505
	        "public interface Test<T extends Number> {\n" +
506
	        "    public <U> void test(Test<U> t, U value);\n" +
507
	        "    public void setValue(T v);" +
508
	        "}"
509
	    },
510
	    "----------\n" + 
511
		"1. ERROR in Test.java (at line 2)\n" + 
512
		"	public <U> void test(Test<U> t, U value);\n" + 
513
		"	                          ^\n" + 
514
		"Bound mismatch: The type U is not a valid substitute for the bounded parameter <T extends Number> of the type Test<T>\n" + 
515
		"----------\n");
516
}
382
}
517
}

Return to bug 282152