From fdc042db41a9ca7e5ed871335bf8c932a1a87616 Mon Sep 17 00:00:00 2001 From: Yoni Fihrer Date: Mon, 31 Jan 2022 05:20:04 +0200 Subject: [PATCH] Fix(sigmatch): allow `varargs[T]` to accept overloaded symbol There was a bug that params wouldn't be matched if the param was overloaded and the candidate type was varargs. This checks the base type of the `varargs` and then will to an overloaded symbol if in a macros or template. Fixes https://github.com/nim-lang/Nim/issues/19446 Fixes https://github.com/nim-lang/Nim/issues/13913 --- compiler/sigmatch.nim | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index e1195d04aaee7..130f2217eff12 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -2233,8 +2233,13 @@ proc paramTypesMatch*(m: var TCandidate, f, a: PType, # XXX this is still all wrong: (T, T) should be 2 generic matches # and (int, int) 2 exact matches, etc. Essentially you cannot call # typeRel here and expect things to work! - let r = typeRel(z, f, arg[i].typ) + var r = typeRel(z, f, arg[i].typ) incMatches(z, r, 2) + if r == isNone: + if userConvMatch(c, m, f, a, arg) == nil and f.kind == tyVarargs: + if f.n == nil: + if typeRel(m, base(f), a) == isGeneric: + r = typeRel(m, base(f), a) if r != isNone: z.state = csMatch case x.state @@ -2258,6 +2263,9 @@ proc paramTypesMatch*(m: var TCandidate, f, a: PType, # See tsymchoice_for_expr as an example. 'f.kind == tyUntyped' should match # anyway: if f.kind in {tyUntyped, tyTyped}: result = arg + elif m.calleeSym != nil and m.calleeSym.kind in {skMacro, skTemplate} and + f.kind == tyVarargs: + result = arg else: result = nil else: # only one valid interpretation found: