I have a function lets say:
proc partTwo(input: string): string {.exportpy}=
var
ans: newSeq[string](8)
set: newSeq[bool](8)
i = 0
while true:
if set.all(proc (x: bool):bool= x):
break
ans[i] = "a"
set[i] = true
i++
return ans.join("")
Notice I made a mistake in line 2, and 3, I put : instead of = and another in line 12 i++. When I try to compile this, instead of the compiler pointing that out, It gives a totally different error Error: invalid indentation even though there was no problem with my indentation. When I fix the mistake, the errors go. Is this a bug, or to be expected ? Also could this have to do with the fact that I'm using nimpy to export it into another python function?
Compiler Version 1.7.1
The issue is the i++ it's looking for the right hand of ++ (nim doesnt have unary postfx operators) so it needs a right hand to the ++. Changing it to either inc i or i += 1 resolves the issue. Furthermore you can rewrite this more elegantly with a set[0..7] as follows:
import std/strutils
proc partTwo(input: string): string =
var
ans = newSeq[string](8)
set: set[0..7]
i = 0
while true:
if set.len == 8:
break
ans[i] = "a"
set.incl i
inc i
return ans.join("")
To answer your question, it is not uncommon for nim to give wrong message information. Runtime errors are even worse, they will skip templates for example (If you use one template two times in the same function, you will need to add some echoes here and there to locate the source of the error).
In your case, inspecting the context (var declaration, call syntax that doesn't return a type after a colon) would be useful to improve error messages. In my opinion, this should be the most important aspect that nim needs to improve, I'm tired of wasting time figuring out what the real problem is.