Skip to content

Commit

Permalink
use type symbol position field instead
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Apr 15, 2023
1 parent ce184ce commit a3c0d35
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 30 deletions.
5 changes: 3 additions & 2 deletions compiler/ast.nim
Original file line number Diff line number Diff line change
Expand Up @@ -920,8 +920,9 @@ type
# for modules, an unique index corresponding
# to the module's fileIdx
# for variables a slot index for the evaluator
# for routines the minimum required parameters
# (could be part of the type but no space there)
# for routine type symbols the minimum required
# parameters (could be part of the type but no
# space for an integer there)
offset*: int # offset of record field
loc*: TLoc
annex*: PLib # additional fields (seldom used, so we use a
Expand Down
11 changes: 5 additions & 6 deletions compiler/semtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1405,12 +1405,11 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode,
onDef(a[j].info, arg)
a[j] = newSymNode(arg)

if not isType:
# routine symbol for which the params are being checked
let s = result.owner
if s != nil:
# set the position field to the minimum number of required parameters
s.position = requiredCount
# generate sym for routine type to set position field to
if result.sym == nil:
result.sym = symFromType(c, result, n.info)
# set the position field to the minimum number of required parameters
result.sym.position = requiredCount

var r: PType
if n[0].kind != nkEmpty:
Expand Down
8 changes: 4 additions & 4 deletions compiler/sigmatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2447,11 +2447,11 @@ proc matchesAux(c: PContext, n, nOrig: PNode, m: var TCandidate, marker: var Int
noEagerParamCountMatch notin c.config.legacyFeatures and
(when defined(nimsuggest): c.config.ideCmd notin {ideSug, ideCon} else: true):
# routine symbols precalculate minimum argument count in `position` field
# if there is no routine symbol, don't bother calculating
if m.callee.kind == tyProc and m.calleeSym != nil and
m.calleeSym.kind in skProcKinds:
# of type symbol
# if there is no routine type symbol, don't bother calculating
if m.callee.kind == tyProc and m.callee.sym != nil:
# if this is unset, it's 0 by default, which matches everything anyway:
let minCount = m.calleeSym.position
let minCount = m.callee.sym.position
if givenCount < minCount:
m.firstMismatch.kind = kMissingParam
a = givenCount + 1
Expand Down
18 changes: 0 additions & 18 deletions tests/template/toverloadeduntypedparam.nim
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,3 @@ block:
fun2(true, nonexistant) # ok
fun2(1, nonexistant) # ok
discard fun2(nonexistant)

block: # make sure using position field is compatible
template code: untyped =
type Foo = object
x, y, z: int
p: proc ()
let a = 1
let b = 2
let c = 3
let p = proc() = discard
p()
let foo = Foo(x: a, y: b, z: c, p: p)
foo.p()
proc bar(x, y, z: int, p: proc()) =
p()
bar(a, b, c, p)
static: code()
code()

0 comments on commit a3c0d35

Please sign in to comment.