Skip to content

Commit

Permalink
Fix(sigmatch): allow varargs[T] to accept overloaded symbol
Browse files Browse the repository at this point in the history
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 #19446 &
#13913
  • Loading branch information
ynfle committed Feb 3, 2022
1 parent 772ed5e commit 776c999
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion compiler/sigmatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2234,8 +2234,14 @@ 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:
let baseRel = typeRel(m, base(f), a)
if baseRel == isGeneric:
r = baseRel
if r != isNone:
z.state = csMatch
case x.state
Expand All @@ -2259,6 +2265,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:
Expand Down

0 comments on commit 776c999

Please sign in to comment.