This commit is contained in:
Andreas Rumpf 2017-06-29 20:25:42 +02:00
commit ac63a99892
2 changed files with 20 additions and 5 deletions

View file

@ -1248,17 +1248,21 @@ proc genSym(p: PProc, n: PNode, r: var TCompRes) =
r.kind = resVal r.kind = resVal
proc genDeref(p: PProc, n: PNode, r: var TCompRes) = proc genDeref(p: PProc, n: PNode, r: var TCompRes) =
if mapType(p, n.sons[0].typ) == etyObject: let it = n.sons[0]
gen(p, n.sons[0], r) let t = mapType(p, it.typ)
if t == etyObject:
gen(p, it, r)
else: else:
var a: TCompRes var a: TCompRes
gen(p, n.sons[0], a) gen(p, it, a)
r.kind = resExpr r.kind = resExpr
if a.typ == etyBaseIndex: if a.typ == etyBaseIndex:
r.res = "$1[$2]" % [a.address, a.res] r.res = "$1[$2]" % [a.address, a.res]
elif n.sons[0].kind == nkCall: elif it.kind == nkCall:
let tmp = p.getTemp let tmp = p.getTemp
r.res = "($1 = $2, $1[0])[$1[1]]" % [tmp, a.res] r.res = "($1 = $2, $1[0])[$1[1]]" % [tmp, a.res]
elif t == etyBaseIndex:
r.res = "$1[0]" % [a.res]
else: else:
internalError(n.info, "genDeref") internalError(n.info, "genDeref")

View file

@ -2,7 +2,8 @@ discard """
output: '''0 output: '''0
5 5
0 0
5''' 5
@[1, 2]'''
""" """
# bug #2476 # bug #2476
@ -33,3 +34,13 @@ proc main =
echo t.m echo t.m
main() main()
# bug #5974
type
View* = object
data: ref seq[int]
let a = View(data: new(seq[int]))
a.data[] = @[1, 2]
echo a.data[]