Repository navigation
Parse a switch guard that calls a function named async - #8935
Conversation
Why:
The async arrow lookahead also ran in guards, where the case's `=>`
follows the guard, so `if async(x) =>` was read as an async arrow.
Async arrows now skip the lookahead in the positions where other arrows
already do: guards and conditions. Fixes #8933.
AST modified (switch guard):
Example:
let async = x => x > 0
let f = v =>
switch v {
| Some(x) if async(x) => 1
| _ => 0
}
Before (diagnostic):
Did you forget a `=>` here?
After (expanded):
let f [arity:1]v =
match v with
| Some x when async x -> 1
| _ -> 0
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Fc7LEuyEfynjaKCVEBPmTF
Signed-off-by: Christoph Knittel <ck@cca.io>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #8935 +/- ##
=======================================
Coverage 81.13% 81.13%
=======================================
Files 456 456
Lines 63754 63754
=======================================
Hits 51728 51728
Misses 12026 12026
🚀 New features to boost your workflow:
|
rescript
@rescript/belt
@rescript/darwin-arm64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
|
Developer playground preview: https://rescript-lang.github.io/rescript/dev-playground/?version=pr-8935 |
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 936b348b96
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Why:
#8935 suppressed the async arrow lookahead in every `WhenExpr`
position, so an async arrow as a switch scrutinee or try body no
longer parsed. Only guards are followed by the case's `=>`.
Guards now have their own parsing context, in which both async and
plain arrows are suppressed; other `WhenExpr` positions suppress plain
arrows only, as before #8935.
AST modified (switch scrutinee):
Example:
let scrutinee = switch async () => 1 {
| _ => 0
}
Before (diagnostic):
Did you forget a `{` here?
After (expanded):
let scrutinee = match async fun [arity:1]() -> 1 with | _ -> 0
Claude-Session: https://claude.ai/code/session_01Fc7LEuyEfynjaKCVEBPmTF
Signed-off-by: Christoph Knittel <ck@cca.io>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Fixes #8933.
To tell an async arrow (
async (x) => …) apart from a call (async(x)), the parser looks ahead for=>after the parentheses. In a switch guard, the case's own=>follows the guard, sowas taken as the start of an async arrow and failed with "Did you forget a
=>here?".Ordinary arrows already skip this lookahead in guards and conditions (the
WhenExprcontext); async arrows now do the same. An arrow is never valid in those positions, since guards and conditions arebool.This matters beyond
async: the generator RFC (#8934) proposesgenas a contextual prefix that works the same way, andgenis a common function name.Test:
parsing/grammar/expressions/async.resgets a guard that callsasync(x)and async arrows as case bodies.🤖 Generated with Claude Code
https://claude.ai/code/session_01Fc7LEuyEfynjaKCVEBPmTF