Bug 83398 - [compiler][1.5] compiler allows adding Object to List<? super Number>
Summary: [compiler][1.5] compiler allows adding Object to List<? super Number>
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Linux-GTK
: P3 normal (vote)
Target Milestone: 3.1 M5   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 84091 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-01-21 09:42 EST by Tom Hofmann CLA
Modified: 2005-02-15 06:38 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tom Hofmann CLA 2005-01-21 09:42:43 EST
I20050118

The following class compiles, but should not (javac complains):

package test1;

import java.util.List;

public class SuperAssignment {
    void method(List<? super Number> list) {
        list.add(new Object());   // should fail
        list.add(new Integer(3)); // correct
    }
}
Comment 1 Dirk Baeumer CLA 2005-01-25 06:50:50 EST
Philippe,

I encounter the same problem when implementing assigment compatibility accross
contexts. I fixed it by distingusish between isAssignmentCompatible and
isTypeArgumentCompatible because both need different rules:

List<? extens Number>= List<Integer> 

  but

? extends Number != Integer

List<? super Number>= List<Object>

  but

? super Number != Object
Comment 2 Dirk Baeumer CLA 2005-01-25 10:27:43 EST
Another case:

public class A<T extends Number> {
	List<? super T> lhs;
	List<? extends Number> rhs;
	{
		lhs.add(rhs.get(0));
	}
}

Javac rejects this
Comment 3 Dirk Baeumer CLA 2005-01-25 10:34:34 EST
Another case:

public class A<U extends Number> {
	List<? super Number> lhs;
	List<? super U> rhs;
	{
		lhs.add(rhs.get(0));
	}
}
Comment 4 Dirk Baeumer CLA 2005-01-25 10:51:48 EST
public class A<U extends Number> {
	List<? super Integer> lhs;
	List<? extends Number> rhs;
	{
		lhs.add(rhs.get(0));
	}
}
Comment 5 Dirk Baeumer CLA 2005-01-25 10:55:38 EST
import java.util.List;

public class A<U extends Number> {
	List<? super Number> lhs;
	List<? super Integer> rhs;
	{
		lhs.add(rhs.get(0));
	}
}
Comment 6 Philipe Mulet CLA 2005-01-27 17:07:16 EST
Added GenericTypeTest#test475-481.
Problem comes from wrong wildcard SUPER bound check implementation.
Indeed the parameterized type compared ok.

Fixed, thanks for all test cases (all exposing the same one issue)
Comment 7 Philipe Mulet CLA 2005-01-31 18:04:41 EST
*** Bug 84091 has been marked as a duplicate of this bug. ***
Comment 8 Jerome Lanneluc CLA 2005-02-15 06:38:15 EST
Verified in I20050214