From 3a8f7d505b3ddfe724af4237516b1ce46c533758 Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 9 Feb 2015 03:14:25 +0100 Subject: [PATCH] temptyseqs works again --- compiler/sem.nim | 6 ++++-- compiler/semexprs.nim | 33 +++++++++++++++++++-------------- compiler/sempass2.nim | 1 + tests/types/temptyseqs.nim | 2 +- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/compiler/sem.nim b/compiler/sem.nim index 214f471d6..2d69d4213 100644 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -130,9 +130,11 @@ proc commonType*(x, y: PType): PType = elif a.kind == tyTuple and b.kind == tyTuple and a.len == b.len: var nt: PType for i in 0.. 0 and n.sons[0].kind == nkExprColonExpr: - for i in countup(0, sonsLen(n) - 1): + elif sonsLen(n) > 0 and n.sons[0].kind == nkExprColonExpr: + # named tuple? + for i in countup(0, sonsLen(n) - 1): var m = n.sons[i].sons[0] - if m.kind != nkSym: + if m.kind != nkSym: internalError(m.info, "changeType(): invalid tuple constr") return - var f = getSymFromList(newType.n, m.sym.name) - if f == nil: - internalError(m.info, "changeType(): invalid identifier") - return - changeType(n.sons[i].sons[1], f.typ, check) + if tup.n != nil: + var f = getSymFromList(newType.n, m.sym.name) + if f == nil: + internalError(m.info, "changeType(): invalid identifier") + return + changeType(n.sons[i].sons[1], f.typ, check) + else: + changeType(n.sons[i].sons[1], tup.sons[i], check) else: for i in countup(0, sonsLen(n) - 1): - var m = n.sons[i] - var a = newNodeIT(nkExprColonExpr, m.info, newType.sons[i]) - addSon(a, newSymNode(newType.n.sons[i].sym)) - addSon(a, m) - changeType(m, tup.sons[i], check) + changeType(n.sons[i], tup.sons[i], check) + when false: + var m = n.sons[i] + var a = newNodeIT(nkExprColonExpr, m.info, newType.sons[i]) + addSon(a, newSymNode(newType.n.sons[i].sym)) + addSon(a, m) + changeType(m, tup.sons[i], check) of nkCharLit..nkUInt64Lit: if check: let value = n.intVal diff --git a/compiler/sempass2.nim b/compiler/sempass2.nim index ede556a70..5434f4f8e 100644 --- a/compiler/sempass2.nim +++ b/compiler/sempass2.nim @@ -683,6 +683,7 @@ proc track(tracked: PEffects, n: PNode) = for child in n: let last = lastSon(child) if child.kind == nkIdentDefs and last.kind != nkEmpty: + # prevent the all too common 'var x = int' bug: XXX track(tracked, last) for i in 0 .. child.len-3: initVar(tracked, child.sons[i], volatileCheck=false) diff --git a/tests/types/temptyseqs.nim b/tests/types/temptyseqs.nim index f8d22bdb8..2b07ba679 100644 --- a/tests/types/temptyseqs.nim +++ b/tests/types/temptyseqs.nim @@ -5,7 +5,7 @@ discard """ # bug #1708 let foo = { "1" : (bar: @["1"]), - "2" : (baz: @[]) + "2" : (bar: @[]) } # bug #871