diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2017-07-09 13:29:44 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2017-07-09 13:29:44 +0200 |
commit | c1d061bb5aa71a9bccfac0584196d62bf6aeab1f (patch) | |
tree | e8d4ebbf279aed09a22d378fb22629d3cbf1b013 /compiler | |
parent | 6ba9c2b119deffee3d94f18a46b42a3525535226 (diff) | |
download | Nim-c1d061bb5aa71a9bccfac0584196d62bf6aeab1f.tar.gz |
fixes #4898
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/semstmts.nim | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index ee4203299..0b74e7629 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -499,6 +499,13 @@ proc fillPartialObject(c: PContext; n: PNode; typ: PType) = else: localError(n.info, "nkDotNode requires 2 children") +proc setVarType(v: PSym, typ: PType) = + if v.typ != nil and not sameTypeOrNil(v.typ, typ): + localError(v.info, "inconsistent typing for reintroduced symbol '" & + v.name.s & "': previous type was: " & typeToString(v.typ) & + "; new type is: " & typeToString(typ)) + v.typ = typ + proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode = var b: PNode result = copyNode(n) @@ -588,7 +595,7 @@ proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode = # this is needed for the evaluation pass and for the guard checking: v.ast = def if sfThread in v.flags: localError(def.info, errThreadvarCannotInit) - v.typ = typ + setVarType(v, typ) b = newNodeI(nkIdentDefs, a.info) if importantComments(): # keep documentation information: @@ -599,7 +606,7 @@ proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode = addToVarSection(c, result, n, b) else: if def.kind == nkPar: v.ast = def[j] - v.typ = tup.sons[j] + setVarType(v, tup.sons[j]) b.sons[j] = newSymNode(v) addDefer(c, result, v) checkNilable(v) @@ -633,7 +640,7 @@ proc semConst(c: PContext, n: PNode): PNode = if typeAllowed(typ, skConst) != nil and def.kind != nkNilLit: localError(a.info, "invalid type for const: " & typeToString(typ)) continue - v.typ = typ + setVarType(v, typ) v.ast = def # no need to copy if sfGenSym notin v.flags: addInterfaceDecl(c, v) var b = newNodeI(nkConstDef, a.info) |