Bug 209639 - codeSelect does not resolve correct key for implicit method type arguments
Summary: codeSelect does not resolve correct key for implicit method type arguments
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.5 M1   Edit
Assignee: David Audel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-11-13 10:13 EST by Markus Keller CLA
Modified: 2008-08-06 13:38 EDT (History)
3 users (show)

See Also:


Attachments
Proposed fix (14.96 KB, patch)
2008-07-23 05:45 EDT, David Audel CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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