Bug 563374 - [1.10][refactoring] Save action "type inference" converts lambda expression to var
Summary: [1.10][refactoring] Save action "type inference" converts lambda expression t...
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.16   Edit
Hardware: PC Windows 10
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2020-05-19 20:53 EDT by Róbert Kitlei CLA
Modified: 2024-05-01 17:41 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Róbert Kitlei CLA 2020-05-19 20:53:00 EDT
In Eclipse 4.16M2 (Build id: 20200507-0346), activating "Use the local variable type inference where possible" as a save action automatically converts the following valid Java 10+ code:

interface TotalEclipse { void f(); }
interface OfTheHeart   { void f(); }

public class LambdaTesting {
	public static void main(String[] args) {
		TotalEclipse te  = () -> System.out.println();
		OfTheHeart   oth = () -> System.out.println();
	}
}

... into the following invalid code upon saving:

public static void main(String[] args) {
	var te  = () -> System.out.println();
	var oth = () -> System.out.println();
}

Note: if the compiler's compliance level is set to Java 9 or below, then Eclipse gives the proper result: the above incorrect conversion is not done (as vars are not available anyway).

I've set the bug's severity as major, as it's very important that refactorings' results be conservative enough not to produce invalid code, but it can be mitigated by turning the save action feature off until the refactoring is fixed.
Comment 1 Eclipse Genie CLA 2022-05-10 13:45:39 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.

If you have further information on the current state of the bug, please add it. 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.
Comment 2 Eclipse Genie CLA 2024-05-01 17:41:25 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.

If you have further information on the current state of the bug, please add it. 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.