Skip to content

Commit 7e4ddb7

Browse files
committed
sem: in-place update n parameter again
`semOverloadedCall` needs access to the accumulator for the purpose of error reporting, as error reporting is always done using typed parameters. Instead of `resolveOverloads`, `semOverloadedCall` now takes care of creating a copy.
1 parent a52bdb6 commit 7e4ddb7

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

compiler/sem/semcall.nim

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,17 @@ proc semGenericArgs(c: PContext, n: PNode): PNode =
278278
if hasError:
279279
result = c.config.wrapError(result)
280280

281-
proc resolveOverloads(c: PContext, nOrig: PNode,
281+
proc resolveOverloads(c: PContext, n: PNode,
282282
filter: TSymKinds, flags: TExprFlags,
283283
errors: var seq[SemCallMismatch]): TCandidate =
284-
addInNimDebugUtils(c.config, "resolveOverloads", nOrig, filter, errors, result)
284+
## Performs overload resolution for the untyped, static call expression `n`,
285+
## filtered by callee symbol kinds specified by `filter`.
286+
## As arguments are typed, they're written back to `n`, with `errors`
287+
## accumulating all tried-and-rejected overloads.
288+
addInNimDebugUtils(c.config, "resolveOverloads", n, filter, errors, result)
285289
var
286290
alt: TCandidate
287-
# `n` itself will be modified, so create a shallow copy first
288-
n = copyNodeWithKids(nOrig)
291+
nOrig = copyNodeWithKids(n)
289292
f = n[0]
290293

291294
case f.kind
@@ -389,9 +392,7 @@ proc resolveOverloads(c: PContext, nOrig: PNode,
389392
if {nfDotField, nfDotSetter} * n.flags != {}:
390393
# clean up the inserted ops
391394
n.sons.delete(2)
392-
nOrig.sons.delete(2)
393395
n[0] = f
394-
nOrig[0] = f
395396
# make sure that all recorded diagnostics are emitted, by adding them to
396397
# the no-match candidate
397398
result.addAllDiagnostics(diags)
@@ -591,6 +592,9 @@ proc semOverloadedCall(c: PContext, n: PNode,
591592
addInNimDebugUtils(c.config, "semOverloadedCall", n, result)
592593
var errors: seq[SemCallMismatch]
593594

595+
let n = copyNodeWithKids(n)
596+
# `n` will be updated with the typed arguments, so a shallow copy has to
597+
# be created
594598
var r = resolveOverloads(c, n, filter, flags, errors)
595599
emitDiagnostics(c, r) # always emit all captured diags for the match
596600
if r.state == csMatch:

0 commit comments

Comments
 (0)