Clean up compiler parity leftovers#8174
Conversation
📝 WalkthroughWalkthroughThe PR removes one codegen error variant, adds optional source locations to symbols, records them for global and nonlocal declarations, uses them in symbol-table validation, and passes synthesized source text into AST compile syntax errors. ChangesSource-location error reporting
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/codegen/src/symboltable.rs`:
- Around line 3361-3363: The global/nonlocal handling in symbol registration is
using the statement-wide range instead of each identifier’s own range, so errors
for later names point to the wrong place. Update the `Stmt::Global` and
`Stmt::Nonlocal` call sites in `symboltable.rs` to pass each name’s range (or
use `register_ident(name, ...)` for per-name registration) rather than
`statement.range()`. Keep the change aligned with the
`register_ident`/`symbol.location` flow so each declared name gets its own
location.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: d89dab1f-1a63-483d-9e25-0a7e4d36bab9
📒 Files selected for processing (3)
crates/codegen/src/error.rscrates/codegen/src/symboltable.rscrates/vm/src/stdlib/_ast.rs
💤 Files with no reviewable changes (1)
- crates/codegen/src/error.rs
| if matches!(role, SymbolUsage::Global | SymbolUsage::Nonlocal) { | ||
| symbol.location = location; | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Store the per-name range for global/nonlocal declarations.
Line 3361 now persists the passed location, but the Stmt::Global/Stmt::Nonlocal callers pass statement.range() for every declared name. For nonlocal a, b, an error for b will point at the statement start instead of the offending identifier. Prefer calling register_ident(name, ...) or passing name.range.
Suggested fix
- self.register_name(name.as_str(), SymbolUsage::Global, statement.range())?;
+ self.register_ident(name, SymbolUsage::Global)?;
- self.register_name(
- name.as_str(),
- SymbolUsage::Nonlocal,
- statement.range(),
- )?;
+ self.register_ident(name, SymbolUsage::Nonlocal)?;🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@crates/codegen/src/symboltable.rs` around lines 3361 - 3363, The
global/nonlocal handling in symbol registration is using the statement-wide
range instead of each identifier’s own range, so errors for later names point to
the wrong place. Update the `Stmt::Global` and `Stmt::Nonlocal` call sites in
`symboltable.rs` to pass each name’s range (or use `register_ident(name, ...)`
for per-name registration) rather than `statement.range()`. Keep the change
aligned with the `register_ident`/`symbol.location` flow so each declared name
gets its own location.
follow-up #8138
Summary by CodeRabbit