Skip to content

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

Draft
cknitt wants to merge 1 commit into
masterfrom
async-guard-lookahead
Draft

cknitt wants to merge 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 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Fc7LEuyEfynjaKCVEBPmTF
Signed-off-by: Christoph Knittel <[email protected]>
@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

This branch has not been deployed

No deployments
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

1 participant