From e9d6f5a647bcfbced69212befdea44c4e77cc205 Mon Sep 17 00:00:00 2001 From: Araq Date: Fri, 30 Dec 2011 21:00:38 +0100 Subject: bugfix: preliminary symbol declaration in first pass of generics --- compiler/lookups.nim | 5 ++++- compiler/msgs.nim | 2 ++ compiler/semgnrc.nim | 20 +++++++++++--------- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/compiler/lookups.nim b/compiler/lookups.nim index ca11896c5..b2ae0d843 100755 --- a/compiler/lookups.nim +++ b/compiler/lookups.nim @@ -68,7 +68,10 @@ proc AddSym*(t: var TStrTable, n: PSym) = proc addDecl*(c: PContext, sym: PSym) = if SymTabAddUnique(c.tab, sym) == Failure: LocalError(sym.info, errAttemptToRedefine, sym.Name.s) - + +proc addPrelimDecl*(c: PContext, sym: PSym) = + discard SymTabAddUnique(c.tab, sym) + proc addDeclAt*(c: PContext, sym: PSym, at: Natural) = if SymTabAddUniqueAt(c.tab, sym, at) == Failure: LocalError(sym.info, errAttemptToRedefine, sym.Name.s) diff --git a/compiler/msgs.nim b/compiler/msgs.nim index 50afd47f9..04149ef49 100755 --- a/compiler/msgs.nim +++ b/compiler/msgs.nim @@ -549,12 +549,14 @@ proc handleError(msg: TMsgKind, eh: TErrorHandling) = assert(false) # we want a stack trace here if (msg >= fatalMin) and (msg <= fatalMax): if gVerbosity >= 3: assert(false) + assert false quit(1) if (msg >= errMin) and (msg <= errMax): inc(gErrorCounter) options.gExitcode = 1'i8 if gErrorCounter >= gErrorMax or eh == doAbort: if gVerbosity >= 3: assert(false) + assert false quit(1) # one error stops the compiler elif eh == doRaise: raiseRecoverableError() diff --git a/compiler/semgnrc.nim b/compiler/semgnrc.nim index a81347eda..216b5674d 100755 --- a/compiler/semgnrc.nim +++ b/compiler/semgnrc.nim @@ -144,13 +144,15 @@ proc semGenericStmt(c: PContext, n: PNode, var L = sonsLen(n) openScope(c.tab) n.sons[L - 2] = semGenericStmt(c, n.sons[L-2], flags, toBind) - for i in countup(0, L - 3): addDecl(c, newSymS(skUnknown, n.sons[i], c)) + for i in countup(0, L - 3): + addPrelimDecl(c, newSymS(skUnknown, n.sons[i], c)) n.sons[L - 1] = semGenericStmt(c, n.sons[L-1], flags, toBind) closeScope(c.tab) of nkBlockStmt, nkBlockExpr, nkBlockType: checkSonsLen(n, 2) openScope(c.tab) - if n.sons[0].kind != nkEmpty: addDecl(c, newSymS(skUnknown, n.sons[0], c)) + if n.sons[0].kind != nkEmpty: + addPrelimDecl(c, newSymS(skUnknown, n.sons[0], c)) n.sons[1] = semGenericStmt(c, n.sons[1], flags, toBind) closeScope(c.tab) of nkTryStmt: @@ -174,7 +176,7 @@ proc semGenericStmt(c: PContext, n: PNode, toBind) a.sons[L-1] = semGenericStmt(c, a.sons[L-1], flags, toBind) for j in countup(0, L-3): - addDecl(c, newSymS(skUnknown, getIdentNode(a.sons[j]), c)) + addPrelimDecl(c, newSymS(skUnknown, getIdentNode(a.sons[j]), c)) of nkGenericParams: for i in countup(0, sonsLen(n) - 1): var a = n.sons[i] @@ -185,14 +187,14 @@ proc semGenericStmt(c: PContext, n: PNode, toBind) # do not perform symbol lookup for default expressions for j in countup(0, L-3): - addDecl(c, newSymS(skUnknown, getIdentNode(a.sons[j]), c)) + addPrelimDecl(c, newSymS(skUnknown, getIdentNode(a.sons[j]), c)) of nkConstSection: for i in countup(0, sonsLen(n) - 1): var a = n.sons[i] if a.kind == nkCommentStmt: continue if (a.kind != nkConstDef): IllFormedAst(a) checkSonsLen(a, 3) - addDecl(c, newSymS(skUnknown, getIdentNode(a.sons[0]), c)) + addPrelimDecl(c, newSymS(skUnknown, getIdentNode(a.sons[0]), c)) a.sons[1] = semGenericStmt(c, a.sons[1], flags+{withinTypeDesc}, toBind) a.sons[2] = semGenericStmt(c, a.sons[2], flags, toBind) of nkTypeSection: @@ -201,7 +203,7 @@ proc semGenericStmt(c: PContext, n: PNode, if a.kind == nkCommentStmt: continue if (a.kind != nkTypeDef): IllFormedAst(a) checkSonsLen(a, 3) - addDecl(c, newSymS(skUnknown, getIdentNode(a.sons[0]), c)) + addPrelimDecl(c, newSymS(skUnknown, getIdentNode(a.sons[0]), c)) for i in countup(0, sonsLen(n) - 1): var a = n.sons[i] if a.kind == nkCommentStmt: continue @@ -240,17 +242,17 @@ proc semGenericStmt(c: PContext, n: PNode, toBind) a.sons[L-1] = semGenericStmt(c, a.sons[L-1], flags, toBind) for j in countup(0, L-3): - addDecl(c, newSymS(skUnknown, getIdentNode(a.sons[j]), c)) + addPrelimDecl(c, newSymS(skUnknown, getIdentNode(a.sons[j]), c)) of nkProcDef, nkMethodDef, nkConverterDef, nkMacroDef, nkTemplateDef, nkIteratorDef, nkLambda: checkSonsLen(n, bodyPos + 1) - addDecl(c, newSymS(skUnknown, getIdentNode(n.sons[0]), c)) + addPrelimDecl(c, newSymS(skUnknown, getIdentNode(n.sons[0]), c)) openScope(c.tab) n.sons[genericParamsPos] = semGenericStmt(c, n.sons[genericParamsPos], flags, toBind) if n.sons[paramsPos].kind != nkEmpty: if n.sons[paramsPos].sons[0].kind != nkEmpty: - addDecl(c, newSym(skUnknown, getIdent("result"), nil)) + addPrelimDecl(c, newSym(skUnknown, getIdent("result"), nil)) n.sons[paramsPos] = semGenericStmt(c, n.sons[paramsPos], flags, toBind) n.sons[pragmasPos] = semGenericStmt(c, n.sons[pragmasPos], flags, toBind) var body: PNode -- cgit 1.4.1-2-gfad0