Skip to content

fix(compiler): await an async call that returns a range iterator - #552

Merged
paralin merged 1 commit into
s4wave:masterfrom
cogentcore:fix/range-func-key-only
Oct 28, 2026
Merged

paralin merged 1 commit into
s4wave:masterfrom
cogentcore:fix/range-func-key-only

Conversation

@rcoreilly

Copy link
Copy Markdown
Contributor

A range over the result of a call that is async, such as for i := range seq(x) where seq returns an iter.Seq or iter.Seq2 and is async because of what it calls, was lowered as await seq(x)!(yield callback). The await applies to the result of calling the iterator, so it calls the promise of seq(x) as the iterator, which throws TypeError: seq(x) is not a function, and the generated TypeScript does not typecheck (TS2349).

The range value of a function range is now parenthesized with parenthesizeAwaitedExpr when it is awaited, as the range target of a map already is, giving await (await seq(x))!(yield callback).

range_func_async_method_value now also ranges over the iterators returned by an async function, with the key only and with the key and value; it failed with the TypeError before. The full compiler test suite passes.

Cogent Lab's Goal math mode transpiles for i := range x to a range over tensor.Iter(x), which is async under GoScript, so its docs failed on such loops.

A range over the result of an async call, such as for i := range seq(x)
where seq returns an iter.Seq, was lowered as await seq(x)!(yield), which
calls the promise of seq(x) as the iterator: TypeError "seq(x) is not a
function". The awaited call is now parenthesized, as for a map range.

Signed-off-by: Randall C. O'Reilly <oreilly@ucdavis.edu>
@rcoreilly

Copy link
Copy Markdown
Contributor Author

@paralin this one happens to be a blocker for deployment of our websites now. Btw in case it is of relevance for your work, we have a version of the mvm Go interpreter that works well with goscript: https://github.com/cogentcore/mvm/tree/cogentcore -- this is what drives our interactive docs and other online editable Go code. So with this, you can even interactively program Go, all through JS via goscript! :)

@rcoreilly

Copy link
Copy Markdown
Contributor Author

@paralin pinging again in hopes you can merge soon -- thanks!!

@paralin
paralin merged commit c7fc77a into s4wave:master Oct 28, 2026
7 checks passed
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.

2 participants