Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 337815 - [inline] Unnecessary cast while inlining local variable
Summary: [inline] Unnecessary cast while inlining local variable
Status: CLOSED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.7   Edit
Hardware: All All
: P3 minor (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2011-02-22 07:01 EST by Deepak Azad CLA
Modified: 2020-05-10 16:05 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Deepak Azad CLA 2011-02-22 07:01:32 EST
3.7 M5

- Inline x
- Expected : long much = 1;
- Actual: long much = (long) 1;

----------------------------------------
package cast_in;

public class Test {	
	void x() {
		long x = 1;		
		long much = x;
	}
}
----------------------------------------
Comment 1 Markus Keller CLA 2011-02-22 08:22:27 EST
Technically, it's correct, since the line "long x = 1;" contains an implicit cast which we need to make explicit in the general case.

When you try to add special handling for number literals, please take care that you don't break cases where the cast is necessary, e.g. here:

        long x= 0x7fffffff;
        long much= x * 2;

Note that this is not only an issue for large numbers. It's not even safe to leave out the cast on the the literal "1":

        long x= 1;
        long much= x << 32;

I guess the only safe exception we can make is in places where the inlined variable will be subject to the same implicit casting/boxing as the initializer of the original variable.
Comment 2 Deepak Azad CLA 2011-02-22 09:16:20 EST
(In reply to comment #1)
> I guess the only safe exception we can make is in places where the inlined
> variable will be subject to the same implicit casting/boxing as the initializer
> of the original variable.
Yeah, I saw bug 46216. 

The solution for this is not trivial, and we have a quick fix to remove the unnecessary cast. So I am letting it be for now..
Comment 3 Eclipse Genie CLA 2020-05-10 16:05:05 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.