Skip to content

🐛 Fix REPL error attribution by tracking source per span#123

Merged
timfennis merged 3 commits intomasterfrom
bugfix/repl-error-source-tracking
Mar 22, 2026
Merged

🐛 Fix REPL error attribution by tracking source per span#123
timfennis merged 3 commits intomasterfrom
bugfix/repl-error-source-tracking

Conversation

@timfennis
Copy link
Copy Markdown
Owner

@timfennis timfennis commented Mar 22, 2026

Summary

Fixes #29.

  • Adds SourceId newtype and SourceDb registry to ndc_lexer so every Span carries a source_id identifying which source string its byte offsets refer to. Span remains Copy.
  • Interpreter owns a SourceDb and registers each source (REPL line, file, etc.) before lexing, threading the SourceId through the lexer.
  • Diagnostics now use codespan-reporting's multi-file Files trait, looking up the correct source via the span's source_id instead of relying on the caller to pass the right source string.
  • REPL errors that originate in functions defined on previous lines now render against the correct source text.

Test plan

  • All 316 existing tests pass
  • cargo clippy clean
  • Manual REPL test: f := fn x -> x / 0 then f(5) — error should highlight x / 0 in the function definition

🤖 Generated with Claude Code

@timfennis timfennis force-pushed the bugfix/repl-error-source-tracking branch from 3a33dc0 to f0dc42d Compare March 22, 2026 12:21
@timfennis timfennis enabled auto-merge (squash) March 22, 2026 12:23
@timfennis timfennis disabled auto-merge March 22, 2026 12:23
timfennis and others added 3 commits March 22, 2026 13:23
Add SourceId to Span and a SourceDb registry so each span knows which
source string it belongs to. Diagnostics now use codespan-reporting's
multi-file support to render errors against the correct source, even
when a function defined on a previous REPL line triggers a runtime error.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@timfennis timfennis force-pushed the bugfix/repl-error-source-tracking branch from f0dc42d to 658eb57 Compare March 22, 2026 12:23
@timfennis timfennis merged commit 5739e84 into master Mar 22, 2026
1 check passed
@timfennis timfennis deleted the bugfix/repl-error-source-tracking branch March 22, 2026 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect line number reported in repl when error is in a previous command

1 participant