This commit is contained in:
Andreas Rumpf
2017-06-29 20:25:42 +02:00
parent 6f29041f09
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
proc genDeref(p: PProc, n: PNode, r: var TCompRes) =
if mapType(p, n.sons[0].typ) == etyObject:
gen(p, n.sons[0], r)
let it = n.sons[0]
let t = mapType(p, it.typ)
if t == etyObject:
gen(p, it, r)
else:
var a: TCompRes
gen(p, n.sons[0], a)
gen(p, it, a)
r.kind = resExpr
if a.typ == etyBaseIndex:
r.res = "$1[$2]" % [a.address, a.res]
elif n.sons[0].kind == nkCall:
elif it.kind == nkCall:
let tmp = p.getTemp
r.res = "($1 = $2, $1[0])[$1[1]]" % [tmp, a.res]
elif t == etyBaseIndex:
r.res = "$1[0]" % [a.res]
else:
internalError(n.info, "genDeref")

View File

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