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 nim-lang#19446 &
nim-lang#13913
  • Loading branch information
ynfle committed Jan 31, 2022
1 parent 3d63d5b commit 3f420b2
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion compiler/sigmatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit 3f420b2

Please sign in to comment.