Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

[10.1] Redefined async functions don't support named arguments #707

Closed
TheSpyder opened this issue Oct 28, 2022 · 6 comments · Fixed by #708
Closed

[10.1] Redefined async functions don't support named arguments #707

TheSpyder opened this issue Oct 28, 2022 · 6 comments · Fixed by #708
Milestone

Comments

@TheSpyder
Copy link

I'm migrating my codebase to 10.1 and I have functions called async (some external, some let) that were defined long before ReScript considered adding async/await.

Is this supposed to be allowed now that async is a keyword? Simple functions work, but functions with named arguments throw a syntax error after the function call such as Did you forget a => here? when I attempt to call them:

let async = (~a, b) => a+b
let _ = async(~a=1, 1)

I'm happy to say redefining async shouldn't be allowed, but then let async and external async should trigger an error rather than at the call site.

@cristianoc
Copy link
Contributor

async is not a keyword, as you're observing.
The second line looks like might be recognised by the parser as the beginning of a function definition. Would you move this to the syntax repo? It could be that when => is missing, the case could be handled differently when in an async context. Since it's a syntax error, there's low risk trying to change that case see what happens. Though it could be that some complex backtracking is required in which case one would have to assess whether it's worth it.

So this is clearly an error:

let _ = (~a=1, 1)

but this (after desugaring)

 let _ = @res.async (~a=1, 1)

could be handled differently

@TheSpyder
Copy link
Author

I don't have move access 🤔 or did you want me to close and re-log?

@cristianoc
Copy link
Contributor

Let me do it.

@cristianoc cristianoc transferred this issue from rescript-lang/rescript-compiler Oct 28, 2022
@cristianoc cristianoc added this to the v11.0 milestone Oct 28, 2022
@TheSpyder
Copy link
Author

Example of redefined async function that works:

let async = (a, b) => a+b
let r = async(1, 1)

@cristianoc
Copy link
Contributor

Here: #708

cristianoc added a commit that referenced this issue Oct 28, 2022
#708)

* Fix issue where async as an id cannot be used with application and labelled arguments.

Fixes #707

* Add parsing test.
@TheSpyder
Copy link
Author

Thank you! I'll test it as soon as I can.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants