fix: Nested fn declarations not inferred as async with Promise.await#971
Merged
milkyskies merged 4 commits intomainfrom Apr 3, 2026
Merged
fix: Nested fn declarations not inferred as async with Promise.await#971milkyskies merged 4 commits intomainfrom
milkyskies merged 4 commits intomainfrom
Conversation
Four async-detection functions only recognized the qualified
`Promise.await` member pattern, missing the bare `Identifier("await")`
shorthand. This caused the generated TypeScript to contain `await`
inside a non-async function.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
mark_async_functions only checked top-level fn declarations and arrows. Nested fn declarations (e.g. handleDragEnd inside a React component) were never marked async, causing generated TS to have await in a non-async function. Also detect bare `|> await` shorthand in all four async-detection sites. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
expr_contains_await was missing Match recursion and Block const values, so match arm IIFEs weren't wrapped as async when the body contained Promise.await. This caused `await` to appear inside non-async IIFEs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Error E041 when a function uses `|> await` but return type is not `Promise<T>`, paralleling how `?` requires `Result<T, E>` - Unannotated async functions now infer `Promise<T>` return type (affects hover display and call-site type checking) - Updated docs to use bare `|> await` shorthand and document the return type requirement closes #972 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
fndeclarations (e.g.handleDragEndinside a React component) were never markedasyncbymark_async_functions, which only checked top-level functions and arrows. This caused generated TypeScript to haveawaitinside a non-async function.|> awaitshorthand (sugar for|> Promise.await) was also not detected by any of the four async-detection functions, causing the same issue even at the top level.Changes
checker.rs: Extendedmark_async_functionswalker to also processItemKind::FunctioninsideBlock/Collectexpressions. AddedIdentifier("await")detection tobody_has_promise_await.checker/items.rs: Added bareawaitdetection tois_promise_await_member.codegen/expr.rs: Added bareawaitdetection toexpr_contains_await.interop/tsgo/probe_gen.rs: Added bareawaitdetection tois_promise_await_member.codegen/tests.rs: Added 4 regression tests covering both bugs.Test plan
cargo test— all tests pass including new regression testscargo fmt— no formatting issues🤖 Generated with Claude Code