The following code returns an error that I don't quite know how to handle:
import critbits
proc `==`[T](a, b: TCritBitTree[T]): bool =
if a.len != b.len:
return
for key, val in a:
if b[key] != val:
return
return true
when isMainModule:
var x, y: TCritBitTree[int]
assert(x == y)
The error message:
> nimrod c -r --verbosity=0 *_test.nim
lib/nimrod/pure/collections/critbits.nim(122, 6) Hint: 'n' is declared but not used [XDeclaredButNotUsed]
word_count_test.nim(13, 11) Info: instantiation from here
word_count_test.nim(7, 7) Error: for a 'var' type a variable needs to be passed
Uh, I figured it out myself: I need to pass a and b as var TCritBitTree[T].
But can somebody explain why this is necessary? I clearly don't want to change a or b. (The error message could be improved too…)
For some reason the header of [] is declared as:
proc `[]`*[T](c: var TCritBitTree[T], key: string): T {.inline.}
Which is wrong. Please fill in a bug report.