-
Notifications
You must be signed in to change notification settings - Fork 243
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
Fix #419 by disallowing bitwise operations on fields during type checking #687
Conversation
Example of what these errors look like:
|
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 PR is good. I left one question but it is non-blocking. When CI passes we can merge
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 looks good to me now
Related issue(s)
Resolves #419
Description
Summary of changes
This PR makes it a type error to use any of
&
,|
,^
,<<
, or>>
on aField
type. The error message suggests users cast to a sized integer type beforehand.In the case the operand types for a bitwise operator are still unknown, this PR introduces a delayed type error that is checked when the function as a whole is finished. This allows for cases like
let x: u8 = 2 << 3;
to be valid as the types of2
and3
are later resolved tou8
, while still keeping ambiguous cases invalid. If the types are still ambiguous when the function is finished type checking, an error is issues explaining type annotations are needed to know how many bits to perform the bitwise operations on.Test additions / changes
None
Checklist
cargo fmt
with default settings.Additional context
The delayed type error mechanism added by this PR is a workaround over splitting
PolymorphicInt
intoPolymorphicInt
andPolymorphicIntOrField
which turned out to be more work.