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

foldr raises IndexError when called on sequence #14404

Closed
refracted opened this issue May 20, 2020 · 1 comment · Fixed by #14413
Closed

foldr raises IndexError when called on sequence #14404

refracted opened this issue May 20, 2020 · 1 comment · Fixed by #14413

Comments

@refracted
Copy link

Example

echo toSeq(1..10).foldr(a + b)

Current Output

Error: unhandled exception: index 10 not in 0 .. 9 [IndexError]

Expected Output

55

What works

The following all work as expected.

echo foldr(toSeq(1..10), a + b)

echo foldl(toSeq(1..10), a + b)

echo toSeq(1..10).foldl(a + b)

nim version

$ nim -v
Nim Compiler Version 1.2.0 [Linux: amd64]
@timotheecour
Copy link
Member

timotheecour commented May 21, 2020

woks at proc scope, fails at module and block scope (as of 16003bf 1.3.5)

import sequtils
template fun = echo toSeq(1..10).foldr(a + b)
proc main=fun()
main() # works
block: fun() # fails
fun() # fails

@refracted always check against latest devel when reporting issues (in this case it does fail in devel, but oftentimes it's a bug that was recently fixed in devel); also make sure example is self contained (i had to add import sequtils); other than that it's a good, valid bug report

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