For smallest example I've found, scroll down to bottom.
I was working on some templates akin to the code down below. With this order everything compiles and works as I expect it to:
var vals = [0, 1, 2, 3, 4]
template potato(): int = # 1
vals[item]
template potato(item): int = # 2
vals[item]
template `potato=`(item, value) =
vals[item] = value
for item in 0 .. high(vals):
echo item.potato
# all work:
vals[item] = vals[item] + 10
(item.potato) = potato + 10
(potato) = item.potato + 10
potato = item.potato + 10
item.potato = potato + 10
echo potato
I discovered though that when I swap places of templates #1 and #2, I get the error
Error: type mismatch: got <template (item: untyped): untyped | template (): untyped>
...
first type mismatch at position: 1
required type for x: varargs[typed]
but expression 'potato' is of type: None
I get the same errors on both devel and stable:
Nim Compiler Version 1.6.4 [Linux: amd64]
git hash: 7994556f3804c217035c44b453a3feec64405758
active boot switches: -d:release
Nim Compiler Version 1.7.1 [Linux: amd64]
git hash: 83dabb69ae0f6c0bb269594a5b73af964b809bc7
active boot switches: -d:release
Even smaller example:
Works:
template potato(): untyped = 0
template potato(item): untyped = 0
echo potato
Doesn't work:
template potato(item): untyped = 0
template potato(): untyped = 0
echo potato
Works:
template potato(item): untyped = 0
template potato(): untyped = 0
echo potato() # note call: '()'
Why does the compiler think that 'potato' is of type: None (<template (item: untyped): int | template (): int, int literal(10)>). Should it not automatically choose the template without the item parameter when I type just 'potato'?