Skip to content

Commit

Permalink
cgmeth: fix the call AST construction
Browse files Browse the repository at this point in the history
Method dispatcher creation didn't account for `var` parameters,
placing them in argument positions directly.
  • Loading branch information
zerbina committed Dec 26, 2024
1 parent b6cbe85 commit 410630b
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions compiler/backend/cgmeth.nim
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,23 @@ proc genDispatcher(g: ModuleGraph; methods: seq[PSym], relevantCols: IntSet) =
if param.typ.skipTypes(abstractInst).kind in {tyRef, tyPtr}:
nilchecks.add newTree(nkCall,
newSymNode(getCompilerProc(g, "chckNilDisp")), newSymNode(param))

proc param(s: PSym): PNode {.nimcall.} =
if s.typ.kind == tyVar:
newTreeIT(nkHiddenAddr, s.info, s.typ,
newTreeIT(nkHiddenDeref, s.info, s.typ.base,
newSymNode(s)))
else:
newSymNode(s)

for meth in 0..high(methods):
var curr = methods[meth] # generate condition:
var cond: PNode = nil
for col in 1..<paramLen:
if contains(relevantCols, col):
var isn = newNodeIT(nkCall, base.info, boolType)
isn.add newSymNode(iss)
let param = base.typ.n[col].sym
isn.add newSymNode(param)
isn.add param(base.typ.n[col].sym)
isn.add newNodeIT(nkType, base.info, curr.typ[col])
if cond != nil:
var a = newNodeIT(nkCall, base.info, boolType)
Expand All @@ -306,8 +314,8 @@ proc genDispatcher(g: ModuleGraph; methods: seq[PSym], relevantCols: IntSet) =
let call = newNodeIT(nkCall, base.info, retTyp)
call.add newSymNode(curr)
for col in 1..<paramLen:
call.add genConv(newSymNode(base.typ.n[col].sym),
curr.typ[col], true, g.config)
call.add genConv(param(base.typ.n[col].sym),
curr.typ[col], true, g.config)
var ret: PNode
if retTyp != nil:
var a = newNodeI(nkFastAsgn, base.info)
Expand Down

0 comments on commit 410630b

Please sign in to comment.