Protect variables in inner scopes. - #484
prozacchiwawa wants to merge 1 commit into
Conversation
…ion so it doesn't need to be feature gated.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 1dfac3c. Configure here.
| if let Some(ceiling) = ceiling { | ||
| if ceiling.len() > idx || (ceiling.len() == idx && target_path[0..idx] != *ceiling) { | ||
| return None; | ||
| } |
There was a problem hiding this comment.
Ceiling check bypassed when BodyOf found first
Medium Severity
In detect_common_cse_root, the BodyOf check at line 443 returns immediately without verifying the ceiling constraint. Since the loop iterates in reverse (deepest to shallowest), if target_path ends with BodyOf (or encounters one before hitting a non-BodyOf element where the ceiling check fires), the function returns that position even if it's above the ceiling. The ceiling check on lines 447–451 only executes for non-BodyOf elements, so it never gets a chance to reject a BodyOf that violates the ceiling constraint.
Reviewed by Cursor Bugbot for commit 1dfac3c. Configure here.


This would have prevented compilation so it doesn't need to be feature gated.
Note
Medium Risk
Medium risk because it changes common-subexpression elimination placement logic in the optimizer, which can subtly affect generated programs and correctness when
assign/letbindings are involved.Overview
Fixes a CSE optimizer bug where a common subexpression could be lifted outside the scope of variables it depends on (notably when one occurrence is inside an
assignbinding expression).The CSE pass now computes a ceiling based on which binding names the subexpression uses, restricts
detect_common_cse_rootaccordingly (skipping the optimization when no safe common root exists), and adds a regression test program (cse-complex-2.clsp) plus a new classic test that compiles and executes it to ensure the result remains correct.Reviewed by Cursor Bugbot for commit 1dfac3c. Bugbot is set up for automated code reviews on this repo. Configure here.