Repository navigation
fix(compiler): await an async call that returns a range iterator - #552
Merged
Merged
Conversation
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>
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! :) |
Contributor
Author
|
@paralin pinging again in hopes you can merge soon -- thanks!! |
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.
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.