Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions compiler/semcall.nim
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,17 @@ proc pickBestCandidate(c: PContext, headSymbol: PNode,
# starts at 1 because 0 is already done with setup, only needs checking
var nextSymIndex = 1
var z: TCandidate # current candidate
let overloadScope = c.currentScope

c.openShadowScope

while true:
determineType(c, sym)
z = initCandidate(c, sym, initialBinding, scope, diagnosticsFlag)
# this is kinda backwards as without a check here the described
# problems in recalc would not happen, but instead it 100%
# does check forever in some cases
if c.currentScope.symbols.counter == symCount:
if overloadScope.symbols.counter == symCount:
# may introduce new symbols with caveats described in recalc branch
matches(c, n, orig, z)

Expand Down Expand Up @@ -198,7 +202,7 @@ proc pickBestCandidate(c: PContext, headSymbol: PNode,
let arg = n[a]
addTypeBoundSymbols(c.graph, arg.typ, name, filter, symMarker, syms)
# reset counter because syms may be in a new order
symCount = c.currentScope.symbols.counter
symCount = overloadScope.symbols.counter
nextSymIndex = 0

# just in case, should be impossible though
Expand All @@ -213,7 +217,10 @@ proc pickBestCandidate(c: PContext, headSymbol: PNode,
sym = syms[nextSymIndex].s
scope = syms[nextSymIndex].scope
inc(nextSymIndex)

if best.state == csMatch and not (best.calleeSym != nil and best.calleeSym.kind in {skTemplate, skMacro}):
c.mergeShadowScope
else:
c.closeShadowScope

proc effectProblem(f, a: PType; result: var string; c: PContext) =
if f.kind == tyProc and a.kind == tyProc:
Expand Down
9 changes: 0 additions & 9 deletions compiler/sigmatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2815,9 +2815,7 @@ proc findFirstArgBlock(m: var TCandidate, n: PNode): int =
else: break

proc matchesAux(c: PContext, n, nOrig: PNode, m: var TCandidate, marker: var IntSet) =

template noMatch() =
c.mergeShadowScope #merge so that we don't have to resem for later overloads
m.state = csNoMatch
m.firstMismatch.arg = a
m.firstMismatch.formal = formal
Expand Down Expand Up @@ -2856,8 +2854,6 @@ proc matchesAux(c: PContext, n, nOrig: PNode, m: var TCandidate, marker: var Int
container: PNode = nil # constructed container
let firstArgBlock = findFirstArgBlock(m, n)
while a < n.len:
c.openShadowScope

if a >= formalLen-1 and f < formalLen and m.callee.n[f].typ.isVarargsUntyped:
formal = m.callee.n[f].sym
incl(marker, formal.position)
Expand Down Expand Up @@ -3021,11 +3017,6 @@ proc matchesAux(c: PContext, n, nOrig: PNode, m: var TCandidate, marker: var Int
noMatch()
checkConstraint(n[a])

if m.state == csMatch and not (m.calleeSym != nil and m.calleeSym.kind in {skTemplate, skMacro}):
c.mergeShadowScope
else:
c.closeShadowScope

inc a
# for some edge cases (see tdont_return_unowned_from_owned test case)
m.firstMismatch.arg = a
Expand Down
Loading