Skip to content

Parse a switch guard that calls a function named async - #8935

Merged
cknitt merged 1 commit into
masterfrom
async-guard-lookahead
Oct 21, 2026
Merged

cknitt merged 1 commit into
masterfrom
async-guard-lookahead

Conversation

@cknitt

@cknitt cknitt commented Oct 20, 2026

Copy link
Copy Markdown
Member

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, so

| Some(x) if async(x) => 1

was 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 WhenExpr context); async arrows now do the same. An arrow is never valid in those positions, since guards and conditions are bool.

This matters beyond async: the generator RFC (#8934) proposes gen as a contextual prefix that works the same way, and gen is a common function name.

Test: parsing/grammar/expressions/async.res gets a guard that calls async(x) and async arrows as case bodies.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Fc7LEuyEfynjaKCVEBPmTF

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>
@github-actions

Copy link
Copy Markdown

@codecov

codecov Bot commented Oct 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.13%. Comparing base (d19633d) to head (936b348).

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           
Files with missing lines Coverage Δ
compiler/syntax/src/res_core.ml 91.99% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pkg-pr-new

pkg-pr-new Bot commented Oct 20, 2026

Copy link
Copy Markdown

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript@8935

@rescript/belt

npm i https://pkg.pr.new/@rescript/belt@8935

@rescript/darwin-arm64

npm i https://pkg.pr.new/@rescript/darwin-arm64@8935

@rescript/linux-arm64

npm i https://pkg.pr.new/@rescript/linux-arm64@8935

@rescript/linux-x64

npm i https://pkg.pr.new/@rescript/linux-x64@8935

@rescript/runtime

npm i https://pkg.pr.new/@rescript/runtime@8935

@rescript/win32-x64

npm i https://pkg.pr.new/@rescript/win32-x64@8935

commit: 936b348

@github-actions

Copy link
Copy Markdown

@cknitt

cknitt commented Oct 21, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-21T08:00:23.379697Z 936b348 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cknitt
cknitt marked this pull request as ready for review October 21, 2026 06:34
@cknitt
cknitt requested a review from cristianoc October 21, 2026 06:35
@cknitt

cknitt commented Oct 21, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread compiler/syntax/src/res_core.ml

@cristianoc cristianoc 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.

Yes

@cknitt
cknitt merged commit 6dd2312 into master Oct 21, 2026
28 checks passed
@cknitt
cknitt deleted the async-guard-lookahead branch October 21, 2026 08:47
cknitt added a commit that referenced this pull request Oct 21, 2026
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>
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.

Switch guard calling a function named async fails to parse

2 participants