-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Incorrect removal property from object accessed in nested conditions #3733
Comments
Looks like an issue with the
|
This is a long-standing assumption of how the collapse properties pass works and is one of the sharpest edges of ADVANCED mode right now (along with quoted vs. unquoted properties). @brad4d may have some longer-term ideas for how to improve usage model here, but in the shorter term the best workaround I know of is use the |
@blickly thanks for your reply. It sounds like you're implying it's by design? However it fails under such a specific pattern that I can't help but think it's a bug. E.g. swap the
Or introduce a variable, and it works as expected:
In a code base with millions of lines of code, and hundreds of developers thats not really an option unless it is very clear what the pattern of incorrect use is. With strings vs dot properties we can say don't mix the two, but not sure how to communicate the anti-pattern that triggers this issue. As far we know we could be hitting this problem hundreds of times in our code base, and only know when on of our users executes the code in production. |
Hmm, that's a very interesting example. For cases like these, I prefer to use the debugger, so that we can see the effects of a single compiler pass in isolation and make sure that the changes aren't caused by other passes that run before, but even in that context, it's easy to reproduce how the CollapseProperties pass is behaving differently with the I think Bradford would be best able to evaluate if this is likely a small fix to how CollapseProperties operates currently, or part of some bigger/more long term issue. |
@WearyMonkey Thanks a lot for reporting this case. I expect to discover why |
Good news! I found the source of the problem and have a fix pending review and testing internally. Basically there was a switch statement that failed to check for the |
Thanks @brad4d ! Appreciate the fast response. Any chance this will be released soon? |
I believe we'll be doing a new release today. |
We have found a case where a property of a conditionally accessed object is incorrectly removed. This is a critical issue as it's impossible to lint for in a large code base and will fail at runtime.
tested versions:
20201126.0.0-nightly
20201102.0.0
source:
output:
expected output:
Notes:
Remove either of the conditions and it works as expected
Move the X variable declaration into
fn
and it works as expected.Inline the
fn
and it works as expected.The text was updated successfully, but these errors were encountered: