-
Notifications
You must be signed in to change notification settings - Fork 59
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
"improve: error msgs and handling" #209
Conversation
Quick question: in mast/mod.rs/42:13: should the constructor 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.
This is great, thanks so much! I'll merge this one but feel free to address the comments in another PR :)
actually I see this is a draft, so let me know when it's good to be merged! |
Panics are now limited to circuit_writer.rs and some constructors |
} | ||
|
||
terms | ||
Ok(terms) | ||
} |
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.
is this necessary @katat ?
Err(Error::new( | ||
"constraint-generation", | ||
ErrorKind::AssertTypeMismatch("rhs", rhs), | ||
span, |
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 think UnexpectedError is still good here, as I don't think we should run into these things (the type checker will catch that before we hit this place)
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.
The main issue that I ran into here is that I wanted to also include res_info.typ in the error message just like in the panic version. format!() returns String and UnexpectedError requires &'static str as its tagged field. Borrowing the String does not last for 'static unless I leak the allocation. In order to get around this, I created this new error variant. The alternative was a slightly more opaque error message. I'm not sure if this is the right thing per se, but worth discussing briefly
src/type_checker/checker.rs
Outdated
.clone(); | ||
|
||
// and is mutable | ||
if !lhs_info.mutable { | ||
return Err(self.error(ErrorKind::AssignmentToImmutableVariable, expr.span)); | ||
if let Some(lhs_info) = lhs_info { |
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.
wait why is lhs_info still an option 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.
I figured out what went wrong here: I didn't handle the Result
with ?
produced from get_type_info()
.get_type_info(&lhs_name) | ||
.or_else(|_| { | ||
Err(self.error(ErrorKind::UnexpectedError("variable not found"), expr.span)) | ||
})? |
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.
you want ok_or
here instead
Lgtm! Thanks so much for the PR! I'll let @katat merge after looking at #209 (comment) |
Looks good, thanks! |
CI should be green now 🫡 |
Closes #26 - removes panics in favor of clear error messages and improves error handling in some places