-
Notifications
You must be signed in to change notification settings - Fork 78
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
Add return types to procedures #1197
Conversation
We use cram tests for this, because the checker cannot create a JSON dump of errors if they occurred on the typechecking step.
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.
First of all, we need a fix to the concrete syntax for return statements.
Second, we need to restrict return types to non-maps, for consistency.
Third, I'd like a few more checks and tests:
- Code that follows a
return
statement is dead, so shouldn't be allowed (note that this may not be needed, depending on how we change the concrete return syntax). For tests, we should also test that this works insidematch
statements. - For procedures with return types all branches of the procedure body should return a value. (Same caveat about return syntax as before)
- Test: A procedure with a return type that is an address type should be able to return a value of a more specific type than the specified return type, and should not be able to return a value of a more general type than the specified return type.
- Test: A returning procedure that calls another returning procedure. This is relevant to test because of the way
EvalUtil.ml
handles return values. Also add a test where the calls go returning->non-returning->returning, just in case.
## RETURN | ||
## | ||
|
||
<YOUR SYNTAX ERROR MESSAGE HERE> |
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.
We should add better error messages to all the new cases in ParserFaults.messages, but let's wait until all the syntax changes of v0.14 are ready.
Thanks for the review!
We should discuss the better syntax, which will be more convenient to developers. I suppose, we want to left semantics and abstract syntax as they're implemented.
Done.
Done for the current implementation.
Done.
Could you please provide a minimal example for this?
Done. The test for dynamic behavior of returns ( |
No, it's the other way around: The actual return address must contain all the fields specified in the procedure signature, but may contain more fields. In other words, the actual address must be assignable to the address in the procedure signature. I think you've implemented the typecheck correctly, but I'd like there to be a test case for it, e.g.:
Also, ideally, a negative test the other way around, just to make sure we're using assignable the right way around. It's not necessary to do extensive testing of |
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.
Looks (broadly) good to me, in that I can't see any obvious bugs...
This PR introduces the
return
keyword and theReturn
statement in the AST:Design decisions in the current implementation:
return
takes as an argument a single variable with the return value. It seems natural for me to use this approach in the ANF-based language.return;
) for early exit when the procedure has no a return type. e.g. the following code is forbidden:return
call is1
. We should discuss and document this constant.scilla-checker
: Use JSON output format for type checking errors #1196TODO:
Eval
supportIterate
statementsCloses #578