-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
conversion to unsigned causes error in VM; works in RT #12700
Comments
It's exactly as the spec says and you know it.
All that happens: You add an explicit bitmask, no need to discuss things, no need for |
The idiomatic way should be Also -1 is signed and conversion from signed to unsigned is checked. It's when you stay in the unsigned domain that it is unchecked. |
No, now it's not checked at runtime and only checked at compile time. |
|
* fix js unsigned integer * better * ref nim-lang#12700 add testcase
ref #18900 static: # illegal conversion from '-2147483648' to '[0..4294967295]'
let x = low(int32)
echo uint32(x)
static: # pass
let x = low(int64)
echo uint64(x) While const x = uint64(-1) # Error: -1 can't |
when use nim check below case, I get messed errors. static:
const x = low(int32)
echo uint32(x)
static: # pass
const x = low(int64)
echo uint64(x)
|
Example
Current Output
But without the
{.compileTime.}
annotationfoo1
works fine and returns"4294967295"
.Expected Output
If conversation to unsigned integers should be unchecked as proposed in the RFC, then the conversation to unsigend should be unchecked at compile time as well.
Possible Solution
Additional Information
The example above is a stripped down version. A real world example would be more that there is some source code out there that you do not have full control over. You would want to use it, but at compile time. But you can't use it at compile time, because interally it uses the the conversion that is range checked at compile time and not range checked at runtime. And then you have to make a PR request to change the conversation into a cast. And maybe get into descussions about
cast
being ugly and compile time evaluation isn't that important etc. It is just friction that can be avoided.This problem is also very annoying for me personally, because I spent a lot of time in the Nim compiler to ensure that both the VM and the runtime behavior of integers is exactly the same. I wrote many tests that ensure in many placed exact same behavior at runtime and compile time. And here the behavior was explicitly broken for reasons that I don't I can't see as important.
This is the commit that introduced that regression c98e0e2
The text was updated successfully, but these errors were encountered: