Bug 255142 - [select] Codeselect should not omit cast
Summary: [select] Codeselect should not omit cast
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.5   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.6 M1   Edit
Assignee: David Audel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-11-13 03:52 EST by Philipe Mulet CLA
Modified: 2009-08-05 02:52 EDT (History)
3 users (show)

See Also:


Attachments
Proposed fix (7.82 KB, patch)
2009-06-25 10:44 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 Philipe Mulet CLA 2008-11-13 03:52:04 EST
3.5M3

Hovering on #bar(...) invocation on line (5) should not show "<Object> Object bar(Object)" instead of "<String> String bar(String)".

The compiler does the right thing, but codeselect seems to ignore the presence of the "(String)" cast in front of selected expression; which leads to generic inference considering expected type (String).

import java.util.List;
public class X {
	void foo(boolean b, Runnable r) {
		Zork z = null;
		String s = (String) bar(z); // 5
	}
	<T> T bar(T t) { return t; }
}
Comment 1 David Audel CLA 2008-11-13 04:01:00 EST
The problem is that the SelectionEngine currently build an AST without the cast expression

import java.util.List;
public class X {
  public X() {
  }
  void foo(boolean b, Runnable r) {
    Zork z;
    String s = <SelectOnMessageSend:bar(z)>;
  }
  <T>T bar(T t) {
  }
}
Comment 2 Mike Wilson CLA 2009-05-05 12:19:22 EDT
Changing Version tag to something more believable.
Comment 3 Philipe Mulet CLA 2009-05-07 10:01:53 EDT
Actually, my original description was wrong.
No inference using type expectation (15.12.2.8) should occur with a cast.
So hover should indicate "<Object> Object bar(Object)".

Now if the cast is removed, it should surface "<String> String bar(String)" as expected type is considered for inference (15.12.2.8).
Comment 4 David Audel CLA 2009-06-25 10:44:11 EDT
Created attachment 140105 [details]
Proposed fix
Comment 5 David Audel CLA 2009-06-25 10:47:06 EDT
Released for 3.6M1

Tests added
  GenericsSelectionTest#test0024()
  ResolveTests_1_5#test0123()

Test updated
  SelectionTest#test19()
Comment 6 Ayushman Jain CLA 2009-08-05 02:51:17 EDT
verified for 3.6M1 using build I20090802-2000