-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parse return type annotation of operations #148
Conversation
Used just to throw an error in the Typer phase
Maybe you could add a neg-test to show the error message? After adding the effekt file to
to generate the check files. Passing |
I've updated the PR text and added a few details about what we (plan to?) do with object operations. |
case None => body checkAgainst tpe | ||
case None => retAnnotation match | ||
|
||
case Some(ret) => // TODO: what about the effects? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// TODO: what about the effects?
That's an interesting question, because it influences the capability passing transformation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be clear that you can only annotate effects, which form a subset of the declared effects. However, we still need to introduce capabilities corresponding to the declared effects, not the annotated one (since the call site cannot know).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's very subtle...
Whatever we do, it should behave similarly to how we deal with annotated effects on functions: effekt/effekt/shared/src/main/scala/effekt/Typer.scala Lines 594 to 614 in 5fa89a2
It is just, that there we do not have any declared effects -- and capability passing should be informed by declared effects, not annotated effects :) |
I think it might be wise to change the scope of this PR. Let's first merge this more-or-less as-is, specifically with parsing return type annotations on all operations and reporting them as errors. [I've updated the body of this PR to reflect this] |
Motivation
When a user mistakenly specifies a type annotation of an operation handler, they get an unfriendly error message from the parser at the wrong place:
This also happens when specifying a return type of a object operation:
Solution
OpHandler
AST to include an optional return type.Typer
phase -- if a return type is specified for an operation, throw an error.Alternative solution
We could also just somehow forbid a return type annotation in the parser, but I haven't been able to do it in a nice way. However, I believe that we want to write down this information from the user even if we decide to ignore it.
Discussion
Is
Typer
the best phase to report this error? We could also report it earlier while in aNamer
orPreTyper
phase, but it seems like this is a typing-related problem that we might want to improve in the future.The solution is not optimal. Ideally, we should take the user-specified return type annotation and somehow take it into consideration for better error messages.
Effect does in fact allow the annotation of the arguments of the handler and even checks them:
Unfortunately, there is an ambiguity about what the return type of an operation handler actually is -- is it the resulting type of the body, or the type of the argument we put into the
resume
continuation?We also don't support annotations on object operations where we should just check the type and compared to the previously defined type in the interface. There are some subtleties to get right -- see comments below for more details.