From 6d951c5b74a7b7d739327469a9501bd07888060e Mon Sep 17 00:00:00 2001 From: Ryan McConnell Date: Sun, 23 Nov 2025 02:10:43 -0500 Subject: [PATCH] init --- compiler/semcall.nim | 13 ++++++++++--- compiler/sigmatch.nim | 9 --------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/compiler/semcall.nim b/compiler/semcall.nim index c07a79f5d1e56..582a397170115 100644 --- a/compiler/semcall.nim +++ b/compiler/semcall.nim @@ -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) @@ -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 @@ -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: diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index a43c41ff7c0b5..1a9892c94eab4 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -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 @@ -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) @@ -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