-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Lean using nat subtraction where int needed #1075
Comments
Although it looks like it shouldn't type check because it's putting a length 7 bitvector into a length 8 place, but I guess the Coe stuff is probably kicking in somehow? |
Yes, the coercion will just silently truncate or pad |
The test in question still seems to be failing on the same line, could be another issue but I don't see any other reason |
It is using the |
Could the |
It's indeed quite messy, with the clean way out of it being to just have a wrapper around |
Could we do a
in |
Is there no way for us to just make
Way back, we used to have both implicit casting and operator overloading in Sail, but I purged the implicit casting from the language because it leads to insanity like this where the ordering between overloading and casting matters. If Lean overloaded to the integer plus and then cast the result to nat it would work.
I think because of how |
Overloading the notation is not really advisable, but we could just have all arithmetic operations be mapped to something like |
For the test
test/c/new_bitfields.sail
we generate (simplifying redundant arithmetic to illustrate the issue):which leads to an off-by-one error as I think lean calculates
(7 - 8) + 1
using natural number subtraction to1
rather than0
.In this case it's particularly subtle because it doesn't cause a compile error it just silently breaks the semantics.
The text was updated successfully, but these errors were encountered: