temptyseqs works again
This commit is contained in:
parent
683b82a2ec
commit
3a8f7d505b
4 changed files with 25 additions and 17 deletions
|
|
@ -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:
|
||||||
|
|
|
||||||
|
|
@ -448,25 +448,30 @@ 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
|
||||||
var f = getSymFromList(newType.n, m.sym.name)
|
if tup.n != nil:
|
||||||
if f == nil:
|
var f = getSymFromList(newType.n, m.sym.name)
|
||||||
internalError(m.info, "changeType(): invalid identifier")
|
if f == nil:
|
||||||
return
|
internalError(m.info, "changeType(): invalid identifier")
|
||||||
changeType(n.sons[i].sons[1], f.typ, check)
|
return
|
||||||
|
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):
|
||||||
var m = n.sons[i]
|
changeType(n.sons[i], tup.sons[i], check)
|
||||||
var a = newNodeIT(nkExprColonExpr, m.info, newType.sons[i])
|
when false:
|
||||||
addSon(a, newSymNode(newType.n.sons[i].sym))
|
var m = n.sons[i]
|
||||||
addSon(a, m)
|
var a = newNodeIT(nkExprColonExpr, m.info, newType.sons[i])
|
||||||
changeType(m, tup.sons[i], check)
|
addSon(a, newSymNode(newType.n.sons[i].sym))
|
||||||
|
addSon(a, m)
|
||||||
|
changeType(m, tup.sons[i], check)
|
||||||
of nkCharLit..nkUInt64Lit:
|
of nkCharLit..nkUInt64Lit:
|
||||||
if check:
|
if check:
|
||||||
let value = n.intVal
|
let value = n.intVal
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue