Bug 97303 - [1.5][compiler] Cannot convert when inferring list of inner parameterized type
Summary: [1.5][compiler] Cannot convert when inferring list of inner parameterized type
Status: CLOSED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 RC2   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-05-30 12:12 EDT by David Saff CLA
Modified: 2005-06-10 11:56 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Saff CLA 2005-05-30 12:12:41 EDT
Against I20050527-1300.

Consider the following code:

>>>>>
package dj.test;

import java.util.Arrays;
import java.util.List;

import junit.framework.TestCase;

public class Deejay extends TestCase {
	class Counter<T> {
	}

	Counter<Song> songCounter = new Counter<Song>();

	Counter<Genre> genreCounter = new Counter<Genre>();

	List<Counter<?>> list1 = Arrays.asList(songCounter, genreCounter);
	List<Counter<? extends Object>> list2 = Arrays.asList(songCounter, genreCounter);
	List<Counter<?>> list3 = Arrays.<Counter<?>>asList(songCounter, genreCounter);
	List<Counter<?>> list4 = Arrays.asList(new Counter<?>[] {songCounter,
genreCounter});
}

class Genre {
}

class Song {
}
<<<<<

list1: compile error: Type mismatch: cannot convert from List<Deejay.Counter<?
extends Object>> to List<Deejay.Counter<?>>
list2: compile error: Type mismatch: cannot convert from List<Deejay.Counter<?
extends Object>> to List<Deejay.Counter<? extends Object>>
list3: fine
list4: fine

Changing Counter to static has no effect.  However, moving it out of Deejay
fixes the compile errors.  There's something about inner parameterized types
that causes the above type mismatches.
Comment 1 Philipe Mulet CLA 2005-05-31 10:52:14 EDT
There are 2 issues in RC1. 

list1: compile error: Type mismatch: cannot convert from List<Deejay.Counter<?
extends Object>> to List<Deejay.Counter<?>>

  Type argument containment should allow ? to be matching ? extends Object 
  at depth 2.

list2: compile error: Type mismatch: cannot convert from List<Deejay.Counter<?
extends Object>> to List<Deejay.Counter<? extends Object>>

  There is one case where we did not pass along the enclosing type of the member   
  type (in Scope#leastContainingInvocation) leading to building a different 
  instance of List<Counter<? extends Object>.

Added GenericTypeTest#test701-702.
Fixed
Comment 2 Philipe Mulet CLA 2005-05-31 10:52:28 EDT
fixed
Comment 3 Philipe Mulet CLA 2005-05-31 12:56:53 EDT
Dirk - good example of compiler semantics evolving
Comment 4 Frederic Fusier CLA 2005-06-07 10:46:36 EDT
Verified for 3.1 RC2 using build N20050607-0010 + JDT/Core HEAD
Comment 5 Jerome Lanneluc CLA 2005-06-10 11:56:02 EDT
Verified with I20050610-0010