Bug 97303

Summary: [1.5][compiler] Cannot convert when inferring list of inner parameterized type
Product: [Eclipse Project] JDT Reporter: David Saff <david>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: dirk_baeumer, markus.kell.r
Version: 3.1   
Target Milestone: 3.1 RC2   
Hardware: PC   
OS: Windows XP   
Whiteboard:

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