From 2e420dfa382dc5af3a225a7b073da2d0eb3d899f Mon Sep 17 00:00:00 2001 From: Parashurama Date: Fri, 12 May 2017 11:21:43 +0200 Subject: fixes multiple nil-checks for methods (#5806) --- compiler/cgmeth.nim | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'compiler') diff --git a/compiler/cgmeth.nim b/compiler/cgmeth.nim index e14306e56..1165ec932 100644 --- a/compiler/cgmeth.nim +++ b/compiler/cgmeth.nim @@ -233,6 +233,12 @@ proc genDispatcher(methods: TSymSeq, relevantCols: IntSet): PSym = var disp = newNodeI(nkIfStmt, base.info) var ands = getSysSym("and") var iss = getSysSym("of") + for col in countup(1, paramLen - 1): + if contains(relevantCols, col): + let param = base.typ.n.sons[col].sym + if param.typ.skipTypes(abstractInst).kind in {tyRef, tyPtr}: + addSon(nilchecks, newTree(nkCall, + newSymNode(getCompilerProc"chckNilDisp"), newSymNode(param))) for meth in countup(0, high(methods)): var curr = methods[meth] # generate condition: var cond: PNode = nil @@ -242,9 +248,6 @@ proc genDispatcher(methods: TSymSeq, relevantCols: IntSet): PSym = addSon(isn, newSymNode(iss)) let param = base.typ.n.sons[col].sym addSon(isn, newSymNode(param)) - if param.typ.skipTypes(abstractInst).kind in {tyRef, tyPtr}: - addSon(nilchecks, newTree(nkCall, - newSymNode(getCompilerProc"chckNilDisp"), newSymNode(param))) addSon(isn, newNodeIT(nkType, base.info, curr.typ.sons[col])) if cond != nil: var a = newNodeIT(nkCall, base.info, getSysType(tyBool)) -- cgit 1.4.1-2-gfad0