From be174fc3c731f1aecf07d7750c038dbb7a018812 Mon Sep 17 00:00:00 2001 From: zah Date: Thu, 23 Mar 2017 13:40:57 +0200 Subject: [PATCH] Fix generic forward declarations; fixes #4104; fixes #4908 (#5566) --- compiler/astalgo.nim | 2 +- compiler/semexprs.nim | 1 - compiler/seminst.nim | 14 +++++++++++--- tests/generics/tforward_generic.nim | 16 ++++++++-------- tests/generics/tforwardgeneric.nim | 18 ++++++++++++++++-- 5 files changed, 36 insertions(+), 15 deletions(-) diff --git a/compiler/astalgo.nim b/compiler/astalgo.nim index 161e4d637..77108eb7b 100644 --- a/compiler/astalgo.nim +++ b/compiler/astalgo.nim @@ -82,7 +82,7 @@ template mdbg*: bool {.dirty.} = elif compiles(L.fileIdx): L.fileIdx == gProjectMainIdx else: - false + error() # --------------------------- ident tables ---------------------------------- proc idTableGet*(t: TIdTable, key: PIdObj): RootRef diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 39113079a..4d698dbfc 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -1433,7 +1433,6 @@ proc semReturn(c: PContext, n: PNode): PNode = proc semProcBody(c: PContext, n: PNode): PNode = openScope(c) - result = semExpr(c, n) if c.p.resultSym != nil and not isEmptyType(result.typ): # transform ``expr`` to ``result = expr``, but not if the expr is already diff --git a/compiler/seminst.nim b/compiler/seminst.nim index 78dd7efe5..71752f5c3 100644 --- a/compiler/seminst.nim +++ b/compiler/seminst.nim @@ -125,6 +125,11 @@ proc addParamOrResult(c: PContext, param: PSym, kind: TSymKind) proc instantiateBody(c: PContext, n, params: PNode, result, orig: PSym) = if n.sons[bodyPos].kind != nkEmpty: + let procParams = result.typ.n + for i in 1 ..