Sitelet https://github.com/starkware-libs/cairo/pull/10088
Skip to content

bugfix(parser): Skipped-token diagnostic spans the token, not its leading comment. - #10088

Merged
orizi merged 1 commit into
mainfrom
orizi/06-11-bugfix_parser_skipped-token_diagnostic_spans_the_token_not_its_leading_comment
Jun 14, 2026
Merged

orizi merged 1 commit into
mainfrom
orizi/06-11-bugfix_parser_skipped-token_diagnostic_spans_the_token_not_its_leading_comment

Conversation

@orizi

@orizi orizi commented Jun 11, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fix the diagnostic span for skipped tokens so that it points to the token itself rather than to any leading trivia (e.g., a comment) that precedes it. Previously, diag_start was set to self.offset before accounting for leading trivia width, causing the reported error span to begin at the start of the leading trivia. Now, text_start is computed by advancing past the leading trivia, and diag_start/diag_end are derived from that position.


Type of change

Please check one:

  • Bug fix (fixes incorrect behavior)
  • New feature
  • Performance improvement
  • Documentation change with concrete technical impact
  • Style, wording, formatting, or typo-only change

Why is this change needed?

When a skipped token was preceded by a leading comment or other trivia, the diagnostic span incorrectly pointed at the beginning of that trivia rather than at the actual skipped token. This made error messages misleading, as the caret would appear under the comment rather than the offending token.


What was the behavior or documentation before?

The error span for a skipped token started at self.offset, which is the position before leading trivia is consumed. For example, a ) preceded by // a leading comment would have its error caret pointing at the comment line rather than at ).


What is the behavior or documentation after?

The error span now starts at text_start, which is self.offset advanced by the total width of the leading trivia. The caret in the diagnostic correctly points at the skipped token itself, not at any preceding comment or whitespace.


Related issue or discussion (if any)


Additional context

Two new test cases are added to skipped_tokens to cover both the skip_until path and the single-token skip path, verifying that the diagnostic span targets the token rather than its leading comment.

@reviewable-StarkWare

Copy link
Copy Markdown

This change is Reviewable

orizi commented Jun 11, 2026 •

Copy link
Copy Markdown
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@orizi
orizi changed the base branch from orizi/06-11-bugfix_compiler_fix_punctuation_newline_of_bare_crate-root_diagnostics to graphite-base/10088 June 11, 2026 16:42
@orizi
orizi force-pushed the orizi/06-11-bugfix_parser_skipped-token_diagnostic_spans_the_token_not_its_leading_comment branch from 2a5cc7b to 8a7a46a Compare June 11, 2026 16:42
@orizi
orizi force-pushed the graphite-base/10088 branch from c61ce65 to 5051f92 Compare June 11, 2026 16:42
@orizi
orizi changed the base branch from graphite-base/10088 to main June 11, 2026 16:42
@orizi
orizi marked this pull request as ready for review June 11, 2026 16:42
@cursor

cursor Bot commented Jun 11, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Parser-only diagnostic positioning change; behavior matches existing append_skipped_token_to_pending_trivia and is covered by a new test.

Overview
Skipped-token diagnostics in skip_until now use the same span logic as single-token skip: diag_start / diag_end are based on text_start (offset after leading trivia), not the pre-token self.offset. Error carets land on the skipped token text instead of preceding comments or whitespace.

A diagnostic test covers fn foo() with a leading comment before a stray ) — the reported span is on ), not the comment line.

Reviewed by Cursor Bugbot for commit b8f2bd0. Bugbot is set up for automated code reviews on this repo. Configure here.

…ding comment.

  skip_until computed the "Skipped tokens" span from self.offset, which
  after take_raw() points at the start of the skipped token's leading
  trivia. A skipped token preceded by a `//` line comment therefore had
  its diagnostic underline the comment instead of the token. Advance past
  the leading trivia (text_start = offset + leading_trivia_width) for both
  the span start and end, mirroring append_skipped_token_to_pending_trivia.
  Adds regression tests to diagnostics/skipped_tokens.
@orizi
orizi force-pushed the orizi/06-11-bugfix_parser_skipped-token_diagnostic_spans_the_token_not_its_leading_comment branch from 8a7a46a to b8f2bd0 Compare June 11, 2026 16:44

@TomerStarkware TomerStarkware left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

@TomerStarkware reviewed 2 files and all commit messages, and made 1 comment.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on eytan-starkware).

@eytan-starkware eytan-starkware left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

@eytan-starkware reviewed 2 files and all commit messages, and made 1 comment.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on orizi).

@orizi
orizi added this pull request to the merge queue Jun 14, 2026
Merged via the queue into main with commit 47ff823 Jun 14, 2026
54 checks passed
@orizi
orizi deleted the orizi/06-11-bugfix_parser_skipped-token_diagnostic_spans_the_token_not_its_leading_comment branch June 14, 2026 11:54
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.

4 participants