Skip to content

Parser: fix while, for, do expression ranges#15369

Merged
T-Gro merged 2 commits into
dotnet:mainfrom
auduchinok:ast-doneRange
Jun 13, 2023
Merged

Parser: fix while, for, do expression ranges#15369
T-Gro merged 2 commits into
dotnet:mainfrom
auduchinok:ast-doneRange

Conversation

@auduchinok
Copy link
Copy Markdown
Member

@auduchinok auduchinok commented Jun 12, 2023

Some of the tokens inserted by LexFilter have unexpected ranges. Consider this case:

while true do
    1

()

There's a ODECLEND token inserted at the () range, to mark an end of the while expression. Using this range allows showing an error in a better place during recovery, but it makes impossible to know where the while actually ends when there's an error inside it or an explicit done keyword is used:

while true do
    2
done

()

This PR adds original/fallback ranges to some of the end-like tokens, so they can be used in parser for calculating the correct ranges of the produced nodes. In this PR only some rules with ODECLEND actually use them, but it makes sense to also update similar cases in other PRs where needed when improving recovery/ranges there later.

It also normalizes ranges of the inner expression nodes produced during recovery.

@auduchinok auduchinok requested a review from a team as a code owner June 12, 2023 13:12
@auduchinok auduchinok closed this Jun 12, 2023
@auduchinok auduchinok reopened this Jun 12, 2023
@auduchinok
Copy link
Copy Markdown
Member Author

This is ready. Please merge it before #15334, and I'll update that PR.

Comment thread src/Compiler/pars.fsy Outdated
@T-Gro T-Gro merged commit e333828 into dotnet:main Jun 13, 2023
@auduchinok auduchinok deleted the ast-doneRange branch June 13, 2023 10:47
T-Gro added a commit that referenced this pull request Apr 15, 2026
- Rename WarnOnLetInSequenceExpression → LetInBodyScoping (no longer a warning)
- Move release notes from Added to Fixed, describe parser behavior change
- Fix AnonModule range in pars.fsy: use last declaration's Range.End
  instead of rhs (which includes OBLOCKEND at EOF position). This is the
  same pattern as PR #12585/#15369 for fixing block-end-derived ranges.
  Fixes the (2,0--3,0) regression to correct (2,0--2,15).
- Add LetIn 08 (do block scoping from WarnExpressionTests)
- Add LetIn 09 (function body scoping from WarnExpressionTests)
- Add LetIn 10 (indentation continuation: c aligns with b, d is separate)
- Update 204 anonymous module baselines (all consistent: end at last
  content character instead of extending to next-line col 0)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
T-Gro added a commit that referenced this pull request Apr 20, 2026
- Rename WarnOnLetInSequenceExpression → LetInBodyScoping (no longer a warning)
- Move release notes from Added to Fixed, describe parser behavior change
- Fix AnonModule range in pars.fsy: use last declaration's Range.End
  instead of rhs (which includes OBLOCKEND at EOF position). This is the
  same pattern as PR #12585/#15369 for fixing block-end-derived ranges.
  Fixes the (2,0--3,0) regression to correct (2,0--2,15).
- Add LetIn 08 (do block scoping from WarnExpressionTests)
- Add LetIn 09 (function body scoping from WarnExpressionTests)
- Add LetIn 10 (indentation continuation: c aligns with b, d is separate)
- Update 204 anonymous module baselines (all consistent: end at last
  content character instead of extending to next-line col 0)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
T-Gro added a commit that referenced this pull request Apr 21, 2026
- Rename WarnOnLetInSequenceExpression → LetInBodyScoping (no longer a warning)
- Move release notes from Added to Fixed, describe parser behavior change
- Fix AnonModule range in pars.fsy: use last declaration's Range.End
  instead of rhs (which includes OBLOCKEND at EOF position). This is the
  same pattern as PR #12585/#15369 for fixing block-end-derived ranges.
  Fixes the (2,0--3,0) regression to correct (2,0--2,15).
- Add LetIn 08 (do block scoping from WarnExpressionTests)
- Add LetIn 09 (function body scoping from WarnExpressionTests)
- Add LetIn 10 (indentation continuation: c aligns with b, d is separate)
- Update 204 anonymous module baselines (all consistent: end at last
  content character instead of extending to next-line col 0)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants