Open ericvw opened 1 year ago
I'm rather new to nim, but I found the question/behavior interesting, so I looked into it.
Your examples made it super easy:
I used ctrl+hover in vscode and there was the solution:
There is a split iterator and a split proc. They live in the same namespace. You can even view them when you navigate into them (ctrl+click in vscode/intellij) type() has the weird property to "prefer" the iter-type.
There was a whole thread about it https://github.com/nim-lang/Nim/issues/8901 Something something assignment, inline..ing, i think it's a side effect of the zero-overhead-iterators.
Hotfix for your specific issue: Put a @() around it, or a .toSeq after it.
Description
When trying to
collect
a table from parsing some string input withsplit
fromstd/strutils
, I encountered a compiler error I don't fully understand. Is this a bug or something I need help understanding about Nim?I distilled my original code down to the following, which reproduces the issue:
Nim Version
Nim Compiler Version 1.6.14 [MacOSX: amd64] Compiled at 2023-07-12 Copyright (c) 2006-2023 by Andreas Rumpf
active boot switches: -d:release
Current Output
Expected Output
Possible Solution
No response
Additional Information
Further investigating, I found something else odd when moving call the
split
outside of the object creation:The compiler hints the variable
s
is unused and the program links.To understand my original issue further, I created the following to understand what type Nim thinks the return value of
split
is:To my surprise, in the last set of
echo
s, it prints as a sequence of strings, but the type isstring
:I am beyond my depth, and I don't know if this is a bug or a known behavior I don't understand. Thanks for looking into this in advance :).