-
Notifications
You must be signed in to change notification settings - Fork 9
Parse command return types #46
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
Conversation
This reverts commit c2d77b5.
| let return_ty = return_ty | ||
| .map(|ty| { | ||
| let AstNode::InOutTypes(types) = self.compiler.get_node(ty) else { | ||
| panic!("internal error: return type is not a return type"); |
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.
This pattern is repeated a lot and is kind of unwieldy. It could use some helper or API refactor. Just a note for the future.
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.
Yeah. I was thinking about a macro
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.
I was thinking along the lines that if we made each AST node its own type, we could use generics, similar to this solution. That would also allow us to deduplicate all the .is_<token>() and .<token>() methods of the Parser.
I'm not a fan of macros since they have different syntax from the rest of Rust, and they can make code hard to read, but sometimes they're helpful.
| name, | ||
| params, | ||
| return_ty: None, | ||
| return_ty, |
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.
I guess the return_ty can be renamed to inout_types or similar at this point.
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.
Good point, I'll update Def if I make a PR in the future related to it.
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 good, thanks! I left some notes/comments but nothing major, merging. |
This PR parses return types for commands and records these in the typechecker, although it doesn't check that the actual result type matches the expected type.
Regarding parsing, I chose to add a
AstNode::InOutTypes(Vec<NodeId>)variant to hold the list of input-output type pairs. Making that list its own node means we can highlight the entire span[ foo -> bar ]in error messages, including the brackets. But if that's not something we need, I can get rid of theInOutTypesvariant and directly store aVec<NodeId>inside eachAstNode::Def. That'd be simpler.