Can someone explain this type A* = object of RootObj p: int type B* = object of A q: int type C* = object of A r: string proc g[T](d: string) = when T is B: let l = (first: -1, last: 0) echo(d.substr(l.first, l.last)) proc g[T]( k: string, d: string) = let l = (first: -1, last: 0) echo(d.substr(l.first, l.last)) proc f[T](d: string): seq[T] = result = newSeq[T]() g[T](d) echo "g[T]( d)" proc f[T](k: string, d: string): seq[T] = result = newSeq[T]() g[T](k, d) echo "g[T](k, d)" let d = "" let t = f[B](d) let sk = f[C]("SM", d) Run
Compiling gives d:\temp\test2.nim(34, 11) template/generic instantiation of `f` from here d:\temp\test2.nim(24, 7) template/generic instantiation of `g` from here d:\temp\test2.nim(16, 17) Error: undeclared identifier: 'l' Run The second call to f resolves to the first definition of f with arity 1 instead of the second one. Changing the first definition of g to proc g[T](d: string) = echo(d) Run makes it compile