Bug 209639

Summary: codeSelect does not resolve correct key for implicit method type arguments
Product: [Eclipse Project] JDT Reporter: Markus Keller <markus.kell.r>
Component: CoreAssignee: David Audel <david_audel>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: jerome_lanneluc, Olivier_Thomann, philippe_mulet
Version: 3.4   
Target Milestone: 3.5 M1   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Proposed fix none

Description Markus Keller CLA 2007-11-13 10:13:12 EST
HEAD

ICodeAssist#codeSelect does not resolve correct key for implicit method type arguments. It should return methods with equal keys on the two emptyList() invocations:

import java.util.Collections;
import java.util.List;

public class Try {
	List<String> get(boolean b) {
		if (b)
			return Collections.<String>emptyList();
		else
			return Collections.emptyList();
	}
}

Currently, the first invocation correctly resolves to:
Ljava/util/Collections;.emptyList<T:Ljava/lang/Object;>()Ljava/util/List<TT;>;%<Ljava/lang/String;>
, whereas the second resolves to:
Ljava/util/Collections;.emptyList<T:Ljava/lang/Object;>()Ljava/util/List<TT;>;%<Ljava/lang/Object;>
...........................................................................................^diff^.

The difference can also be seen in the Javadoc hover, where the first one has the correct header <String> List<String> java.util.Collections.emptyList() but the second one is  <Object> List<Object> java.util.Collections.emptyList().
Comment 1 Jerome Lanneluc CLA 2007-12-14 11:55:15 EST
The SelectionEngine is loosing the return statement:

import java.util.Collections;
import java.util.List;
public class Try {
  public Try() {
  }
  List<String> get(boolean b) {
    <SelectOnMessageSend:Collections.emptyList()>;
  }
}

Thus the inference cannot find out that List<String> should be return.
David, please have a look.
Comment 2 Philipe Mulet CLA 2008-07-15 09:09:54 EDT
Inference from expected type (15.12.2.8) is also meant to work with:
- field initialization expression
- local variable initialization expression
- array initialization

Comment 3 Philipe Mulet CLA 2008-07-16 06:40:35 EDT
e.g. for array initializer:
public class X {
	String[] strings = { foo() };
	static <T> T foo() { return null; }
}
Comment 4 David Audel CLA 2008-07-23 05:45:07 EDT
Created attachment 108177 [details]
Proposed fix
Comment 5 David Audel CLA 2008-07-23 05:49:04 EDT
Released for 3.5M1.

Tests added
  GenericsSelectionTest#test0023()
  ResolveTests_1_5#test0119() -> test0122()
Comment 6 Olivier Thomann CLA 2008-08-06 13:38:40 EDT
Verified for 3.5M1 using I20080805-1307