-
-
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
Compiler crash when using case..of..else with huge ranges #8838
Comments
Thats because you bootstrapped your current compiler without One example of the problematic is the procedure proc lengthOrd*(conf: ConfigRef; t: PType): BiggestInt =
case t.skipTypes(tyUserTypeClasses).kind
of tyInt64, tyInt32, tyInt: result = lastOrd(conf, t)
of tyDistinct: result = lengthOrd(conf, t.sons[0])
else:
let last = lastOrd(conf, t)
let first = firstOrd(conf, t)
# XXX use a better overflow check here:
if last == high(BiggestInt) and first <= 0:
result = last
else:
result = last - first + 1 The length of the ordinals int64, int32, int is clearly not the high value of the corresponding type but rather the high value of the matching unsigned type + 1. (Now this is kind of a problem for int64 because Nim can't represent high(uint64) + 1, but Nim could detect this overflow and handle it gracefully, or simply ignore it as with When Nim tries to detect if you covered all possible values in a case statement it performs a If you write the following pointless case statement: let x = 0'i32
case x of
low(int32)..high(int32): discard Nim will claim that you have not covered all cases, which is evidently nonsense. This is also a consequence of the buggy (Don't try to compile this for the js backend..., see #8821) |
A documented limitation hardly qualifies as a design mistake. Be my guest and improve it. |
Nim now (as of v0.20.99) internally has |
Consider the example:
This code causes the compiler crash on the devel branch with following error:
But on tag 0.18.0 it works fine:
The text was updated successfully, but these errors were encountered: