async/await produces unspecific "type inside generator must be known in this context" error messages #58930
Labels
A-async-await
Area: Async & Await
A-diagnostics
Area: Messages for errors, warnings, and lints
AsyncAwait-Polish
Async-await issues that are part of the "polish" area
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
While trying to write async/await code I encountered lots of error messages with the description
The error is typically displayed at the callsite of the async function, and it's often very unclear what the actual error is. It often seems like the message might be a compiler bug, but I could either find a bug in my code later on or solve it by moving/refactoring things. However it's a bit frustrating to work with, since the message is very unspecific and often does not point to the actual issue. In one case it took me several hours to figure out that a generic bound in a different module (which was neither the caller nor the called async function) was missing in order to enable compilation.
Example:
The following code (playground)
leads to the following error message:
The issue here is an unused type parameter.
Workaround that I discovered much later: Remove the async annotation and call the function as a normal function. That will typically break something else, but often would also show a hint about the real issue.
E.g. if we remove async/await from the example, this error message is displayed:
The text was updated successfully, but these errors were encountered: