Skip to content

Commit

Permalink
fix nim-lang#13182: proc fun(a: varargs[Foo, conv]) now can be over…
Browse files Browse the repository at this point in the history
…loaded
  • Loading branch information
timotheecour committed Feb 7, 2020
1 parent e24443f commit 54cbd36
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/semcall.nim
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ proc semOverloadedCall(c: PContext, n, nOrig: PNode,
# this time enabling all the diagnostic output (this should fail again)
discard semOverloadedCall(c, n, nOrig, filter, flags + {efExplain})
elif efNoUndeclared notin flags:
notFoundError(c, n, errors)
if c.depthSigmatchVarargs == 0: notFoundError(c, n, errors)

proc explicitGenericInstError(c: PContext; n: PNode): PNode =
localError(c.config, getCallLineInfo(n), errCannotInstantiateX % renderTree(n))
Expand Down
5 changes: 5 additions & 0 deletions compiler/semdata.nim
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ type
# would otherwise fail.
unusedImports*: seq[(PSym, TLineInfo)]
exportIndirections*: HashSet[(int, int)]
depthSigmatchVarargs*: int
# for protection against issue #13182:
# when we sigmatch against `fun(a: varargs[Foo, conv])`, this
# calls a nested sigmatch for `conv`, but that nested sigmatch shouldn't
# generate an error by itself before whole overload resolution takes place

template config*(c: PContext): ConfigRef = c.graph.config

Expand Down
4 changes: 4 additions & 0 deletions compiler/sigmatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2456,8 +2456,12 @@ proc matchesAux(c: PContext, n, nOrig: PNode,
m.baseTypeMatch = false
m.typedescMatched = false
n[a] = prepareOperand(c, formal.typ, n[a])
let old = m.c.depthSigmatchVarargs
m.c.depthSigmatchVarargs.inc
arg = paramTypesMatch(m, formal.typ, n[a].typ,
n[a], nOrig[a])
m.c.depthSigmatchVarargs.dec
assert m.c.depthSigmatchVarargs == old
if arg == nil:
noMatch()
return
Expand Down

0 comments on commit 54cbd36

Please sign in to comment.