Declaring variable(s) with no value(s) should default it to `null`

Description

Within functions if you are declaring a variable with var with no value it should default it to null;

 

Activity

Show:

Jon ClausenJune 4, 2024 at 4:55 PM

FYI. Also we will need the compat module to make the declaration an empty string, which is what Lucee does.

Luis MajanoJune 4, 2024 at 4:09 PM

Yes, but this is a concern fo the var keyword, so maybe it shouldn’t just be a shortcut.

Brad WoodJune 4, 2024 at 4:07 PM

This has several issues, mostly concerning ambiguity in the code. Firstly var foo is just a shortcut for local.foo but if you just have

in your code, that’s not as assignment, it’s just a variable access. We have no “declaration” AST node per se, just a BoxAssignment node, which requires a left and right expression. And if we want local.foo to be an assignment, then is this also one?

Now, every single variable access is indistinguishable from just a regular variable access.

If foo doesn’t exist,

now no longer throws an error that foo doesn’t exist, but declares a new variable called foo with a value of null and then passes null to the method.

I think making any variable access, even with no assignment portion be an assignment is a lexical quagmire.

Fixed
Pinned fields
Click on the next to a field label to start pinning.

Details

Assignee

Reporter

Components

Fix versions

Priority

Sentry

Created June 4, 2024 at 3:39 PM
Updated June 10, 2024 at 9:48 AM
Resolved June 10, 2024 at 9:48 AM