Ruby: Fix bug in implicitAssignmentNode#21907
Open
hvitved wants to merge 2 commits into
Open
Conversation
0ef4595 to
c319680
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes Ruby variable-scope/namebinding for the rescue ... => <target> exception-variable assignment when the target is a setter-like expression (e.g. self.name), avoiding incorrectly treating sub-expressions as implicit variable writes and reducing rb/useless-assignment-to-local false positives.
Changes:
- Refines implicit/explicit assignment ancestor traversal in
Variable.qllto only propagate through LHS-assignment container nodes. - Adds a Ruby regression test (
RescueSetter) coveringrescue => self.namesetter behavior. - Updates variable/SSA/access expected outputs for the new test coverage and corrected binding.
Show a summary per file
| File | Description |
|---|---|
| ruby/ql/lib/codeql/ruby/ast/internal/Variable.qll | Restricts recursive “inside assignment” detection to assignment-LHS container parents to avoid misclassifying setter targets. |
| ruby/ql/test/library-tests/variables/scopes.rb | Adds RescueSetter demonstrating exception assignment to a setter-like target in rescue => .... |
| ruby/ql/test/library-tests/variables/varscopes.expected | Updates expected scope ranges to include the new test class/methods. |
| ruby/ql/test/library-tests/variables/variable.expected | Updates expected variable entries/scopes reflecting corrected implicit assignment behavior. |
| ruby/ql/test/library-tests/variables/varaccess.expected | Updates expected variable access/write classifications for the new scenario. |
| ruby/ql/test/library-tests/variables/ssa.expected | Updates expected SSA definitions/reads to match the corrected binding and new test code. |
| ruby/ql/test/library-tests/variables/parameter.expected | Adds expected parameter-variable entries for value and msg from the new test methods. |
Copilot's findings
- Files reviewed: 7/7 changed files
- Comments generated: 0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A small bug fix where in cases like
self.namewas incorrectly marked as updating variables namedselfandname, instead of calling thename=setter.DCA confirms that we remove some
rb/useless-assignment-to-localFPs.