From 8780d25e038ed6ca6815f3ed4aa6a7a58416714b Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Sat, 14 Oct 2017 09:32:57 +0200 Subject: minor refactorings for better destructors --- compiler/semtypinst.nim | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'compiler/semtypinst.nim') diff --git a/compiler/semtypinst.nim b/compiler/semtypinst.nim index a3953d87e..172a557b3 100644 --- a/compiler/semtypinst.nim +++ b/compiler/semtypinst.nim @@ -357,11 +357,17 @@ proc handleGenericInvocation(cl: var TReplTypeVars, t: PType): PType = assert newbody.kind in {tyRef, tyPtr} assert newbody.lastSon.typeInst == nil newbody.lastSon.typeInst = result - let asgn = newbody.assignment - if asgn != nil and sfFromGeneric notin asgn.flags: - # '=' needs to be instantiated for generics when the type is constructed: - newbody.assignment = cl.c.instTypeBoundOp(cl.c, asgn, result, cl.info, - attachedAsgn, 1) + template typeBound(field) = + let opr = newbody.field + if opr != nil and sfFromGeneric notin opr.flags: + # '=' needs to be instantiated for generics when the type is constructed: + newbody.field = cl.c.instTypeBoundOp(cl.c, opr, result, cl.info, + attachedAsgn, 1) + # we need to produce the destructor first here because generated '=' + # and '=sink' operators can rely on it: + if newDestructors: typeBound(destructor) + typeBound(assignment) + typeBound(sink) let methods = skipTypes(bbody, abstractPtrs).methods for col, meth in items(methods): # we instantiate the known methods belonging to that type, this causes -- cgit 1.4.1-2-gfad0