Skip to content
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

Use type cached in ConstValue::Opaque, remove ConstTypeError::Failed #279

Merged
merged 3 commits into from
Jul 25, 2023

Conversation

acl-cqc
Copy link
Contributor

@acl-cqc acl-cqc commented Jul 17, 2023

  • ConstValue::Opaque cached the type, but we never used it - so do so in typecheck_const
  • Whereas ConstTypeError::TypeMismatch gives both expected and actual type, ConstTypeError::Failed gave only the expected type. However, we always have the actual type available via const_type(), so we can alway use the more informative TypeMismatch error

@acl-cqc acl-cqc requested a review from croyzor July 17, 2023 16:35
match (typ, val) {
(ClassicType::Int(exp_width), ConstValue::Int { value, width }) => {
let failure = Err(ConstTypeError::TypeMismatch(typ.clone(), val.const_type()));
match typ {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be neater to keep matching on the pair (typ, val), rather than starting every branch with a let ... else ...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think falling through to returning failure is also neater than returning it in the branches

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, there was a goal besides neatness (that it's easy to miss a case when you match on a pair), but never mind - I did write [subjective] in the title of that commit :-) :-)

I've removed that commit so now am just dropping Failure in favour of only TypeMismatch, how's that?

@acl-cqc acl-cqc force-pushed the new/fewer_const_type_errors branch from 1ca3713 to 87d145f Compare July 18, 2023 08:38
@acl-cqc acl-cqc changed the title More Constant tidies Use type cached in ConstValue::Opaque, remove ConstTypeError::Failed Jul 24, 2023
@acl-cqc acl-cqc merged commit b43b78b into main Jul 25, 2023
6 checks passed
@acl-cqc acl-cqc deleted the new/fewer_const_type_errors branch July 25, 2023 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants