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

Empty limbs when uninitialized #26

Closed
auxym opened this issue Dec 22, 2019 · 2 comments · Fixed by #33
Closed

Empty limbs when uninitialized #26

auxym opened this issue Dec 22, 2019 · 2 comments · Fixed by #33

Comments

@auxym
Copy link

auxym commented Dec 22, 2019

Consider the following:

var
    a: BigInt
    b: BigInt = 12.initBigInt

echo a*b

This results in the following stack trace:

[...]/scratch.nim(7) scratch
[...].nimble/pkgs/bigints-0.4.3/bigints.nim(484) *
[...].nimble/pkgs/bigints-0.4.3/bigints.nim(394) multiplication
[...].choosenim/toolchains/nim-#devel/lib/system/fatal.nim(39) sysFatal
Error: unhandled exception: index out of bounds, the container is empty [IndexError]

This is because a.limbs is @[]. Would it be possible for an uninitialized BigInt to default to limbs = @[0], to be consistent with nim integers? Otherwise, maybe there could be a flag initialized that is checked before trying to operate on a BigInt, so we get slightly more readable errors. I'm not super proud about it, but tbh this took me a while to debug. To be fair, my actual code was slightly more complex and resulted in a zero BigInt not being initialized in a corner case.

@def-
Copy link
Member

def- commented Dec 22, 2019

Sounds good but would require nim-lang/RFCs#126

Alternatively we could handle @[] as the same as @[0]. I'd accept a PR that adds this.

@auxym
Copy link
Author

auxym commented Dec 22, 2019

Yeah, I wasn't sure if/how it could be implemented in Nim. Good to know there's an RFC about it!

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 a pull request may close this issue.

2 participants