Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected error: "Cannot refer to the non-final variable x inside a lambda expression" #209

Open
DiogenesFL17 opened this issue Jul 12, 2020 · 0 comments
Projects

Comments

@DiogenesFL17
Copy link

Issue

I receive a syntax error in VS Code (red squiggles) for variables which evaluate correctly, i.e. openHAB does not log an error when processing the *.rules file, and the logic executes as expected.

Detail

I use lambdas inside Rules mainly to switch between Items in the same Group. For instance, I have Group:DateTime groups which I loop through to calculate times at which lights will turn on and off at dawn and dusk. One of my lambdas formats a string variable in preparation for further logic. This variable is used multiple times as it loops through each Group

var String T_DawnOn_st = ""
// Run through each Dawn/Dusk light group
var GroupItem G_DDLights = ScriptServiceUtil.getItemRegistry.getItem(C_DawnDuskGrpName_st) as GroupItem
G_DDLights.members.forEach[ G_x |	
    var GroupItem G_x_tmp = G_x as GroupItem
    G_x_tmp.members.forEach[ I_x |
        if (I_x.name.endsWith(C_SuffixDawnOnTimeItm_st)) {
            // Next line presents the error on "T_DawnOn_st"
            T_DawnOn_st = I_x.state.format("%1$tH:%1$tM")
        }
        ...
    ]
  ]

The logic executes correctly, so I assume this error should be removed, as openHAB has no problem with the syntax.
The following line
T_DawnOn_st = I_x.state.format("%1$tH:%1$tM")
produces the syntax error (red squiggles):
Cannot refer to the non-final variable T_DawnOn_st inside a lambda expression (org.eclipse.xtext.xbase.validation.IssueCodes.invalid_mutable_variable_access)

Your Environment

openHAB 2.5.6 Release Build on ubuntu
VS Code 1.42.1 on Windows 10 Pro
Chrome 76.0.3809.146
Node.js 12.4.0
VS Code openHAB extension 0.7.0

Here's a link to a fellow openHABian who also had the issue.

@Confectrician Confectrician added this to Language Server in Backlog Apr 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Backlog
  
Language Server
Development

No branches or pull requests

2 participants