Templates seem to sometimes take precedence in overload resolution, which makes it sometimes impossible to introduce template with the same name as (even private) proc in other module:
torder.nim:
type
FooBase = ref object of RootObj
Foo*[T] = ref object of FooBase
proc foobar(v: FooBase): string =
return "FooBase"
proc foobar(v: int): string =
return "int"
proc bar*[T](v: T) =
let val: string = foobar(v)
use_it.nim:
from torder import nil
template foobar(a): expr =
{.error: "not this foobar!" .}
proc mygeneric[T]() =
var f: torder.Foo[int]
torder.bar(f)
mygeneric[int]()
fails to compile with Error: invalid pragma: error: "not this foobar!".
Is this a compiler bug or expected behaviour? The problem seems to only occur with inheritance. If we replace torder.bar(f) with torder.bar(5) the code compiles fine (foobar(int) is selected instead of the template).
It's expected behaviour. Generics matches are preferred over subtype matches: http://nim-lang.org/docs/manual.html#overloading-resolution
That said, maybe an 'untyped' match should not be treated as a generic match. Btw you can do this to prevent this behaviour:
proc bar*[T](v: T) =
bind foobar
let val: string = foobar(v)