You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Yields no error, a.new is called instead of system.new. I think it is correct behavior because T: typedesc of system.new is more general and _: typedesc[seq[T]] of a.new[T] is more specific thus more specific variant gets selected.
a.nim:
import b
discard seq[tuple[k: string, v: string]].new()
b.nim:
proc new*[T](_: typedesc[seq[T]], len = 0.Natural): seq[T] {.inline.} = new_seq[T](len)
nim c b.nim yields Error: ambiguous call; both system.new(T: typedesc) and a.new(_: typedesc[seq[T]], len: Natural) match for: (typedesc[seq[tuple[k: string, v: string]]])
I think proc with more specific type should be preferred instea of generating ambigious call error. Practical usecase as seen from exampleis binding new() constructor to a type while that constructor has no parameters. So far this bug mandates writing seq[string].new(0) instead of seq[string].new() completely negating convenience of default parameter value.
The text was updated successfully, but these errors were encountered:
The compiler also uses scope to disambiguate so if you are in the same module your alternative 'new' gets picked. This needs to be documented at least but I really don't like this behaviour. It's of course required for some template hacking to work. sigh
Consider this:
a.nim:
Yields no error,
a.new
is called instead ofsystem.new
. I think it is correct behavior becauseT: typedesc
ofsystem.new
is more general and_: typedesc[seq[T]]
ofa.new[T]
is more specific thus more specific variant gets selected.a.nim:
b.nim:
nim c b.nim
yields Error: ambiguous call; both system.new(T: typedesc) and a.new(_: typedesc[seq[T]], len: Natural) match for: (typedesc[seq[tuple[k: string, v: string]]])I think proc with more specific type should be preferred instea of generating ambigious call error. Practical usecase as seen from exampleis binding new() constructor to a type while that constructor has no parameters. So far this bug mandates writing
seq[string].new(0)
instead ofseq[string].new()
completely negating convenience of default parameter value.The text was updated successfully, but these errors were encountered: