temptyseqs works again

This commit is contained in:
Araq 2015-02-09 03:14:25 +01:00
commit 3a8f7d505b
4 changed files with 25 additions and 17 deletions

View file

@ -130,9 +130,11 @@ proc commonType*(x, y: PType): PType =
elif a.kind == tyTuple and b.kind == tyTuple and a.len == b.len: elif a.kind == tyTuple and b.kind == tyTuple and a.len == b.len:
var nt: PType var nt: PType
for i in 0.. <a.len: for i in 0.. <a.len:
if isEmptyContainer(a.sons[i]) and not isEmptyContainer(b.sons[i]): let aEmpty = isEmptyContainer(a.sons[i])
let bEmpty = isEmptyContainer(b.sons[i])
if aEmpty != bEmpty:
if nt.isNil: nt = copyType(a, a.owner, false) if nt.isNil: nt = copyType(a, a.owner, false)
nt.sons[i] = b.sons[i] nt.sons[i] = if aEmpty: b.sons[i] else: a.sons[i]
if not nt.isNil: result = nt if not nt.isNil: result = nt
#elif b.sons[idx].kind == tyEmpty: return x #elif b.sons[idx].kind == tyEmpty: return x
elif a.kind == tyRange and b.kind == tyRange: elif a.kind == tyRange and b.kind == tyRange:

View file

@ -448,20 +448,25 @@ proc changeType(n: PNode, newType: PType, check: bool) =
let tup = newType.skipTypes({tyGenericInst}) let tup = newType.skipTypes({tyGenericInst})
if tup.kind != tyTuple: if tup.kind != tyTuple:
internalError(n.info, "changeType: no tuple type for constructor") internalError(n.info, "changeType: no tuple type for constructor")
elif newType.n == nil: discard
elif sonsLen(n) > 0 and n.sons[0].kind == nkExprColonExpr: elif sonsLen(n) > 0 and n.sons[0].kind == nkExprColonExpr:
# named tuple?
for i in countup(0, sonsLen(n) - 1): for i in countup(0, sonsLen(n) - 1):
var m = n.sons[i].sons[0] var m = n.sons[i].sons[0]
if m.kind != nkSym: if m.kind != nkSym:
internalError(m.info, "changeType(): invalid tuple constr") internalError(m.info, "changeType(): invalid tuple constr")
return return
if tup.n != nil:
var f = getSymFromList(newType.n, m.sym.name) var f = getSymFromList(newType.n, m.sym.name)
if f == nil: if f == nil:
internalError(m.info, "changeType(): invalid identifier") internalError(m.info, "changeType(): invalid identifier")
return return
changeType(n.sons[i].sons[1], f.typ, check) changeType(n.sons[i].sons[1], f.typ, check)
else:
changeType(n.sons[i].sons[1], tup.sons[i], check)
else: else:
for i in countup(0, sonsLen(n) - 1): for i in countup(0, sonsLen(n) - 1):
changeType(n.sons[i], tup.sons[i], check)
when false:
var m = n.sons[i] var m = n.sons[i]
var a = newNodeIT(nkExprColonExpr, m.info, newType.sons[i]) var a = newNodeIT(nkExprColonExpr, m.info, newType.sons[i])
addSon(a, newSymNode(newType.n.sons[i].sym)) addSon(a, newSymNode(newType.n.sons[i].sym))

View file

@ -683,6 +683,7 @@ proc track(tracked: PEffects, n: PNode) =
for child in n: for child in n:
let last = lastSon(child) let last = lastSon(child)
if child.kind == nkIdentDefs and last.kind != nkEmpty: if child.kind == nkIdentDefs and last.kind != nkEmpty:
# prevent the all too common 'var x = int' bug: XXX
track(tracked, last) track(tracked, last)
for i in 0 .. child.len-3: for i in 0 .. child.len-3:
initVar(tracked, child.sons[i], volatileCheck=false) initVar(tracked, child.sons[i], volatileCheck=false)

View file

@ -5,7 +5,7 @@ discard """
# bug #1708 # bug #1708
let foo = { let foo = {
"1" : (bar: @["1"]), "1" : (bar: @["1"]),
"2" : (baz: @[]) "2" : (bar: @[])
} }
# bug #871 # bug #871