mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-19 15:31:28 +00:00
fixes #5974
This commit is contained in:
@@ -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")
|
||||
|
||||
|
||||
@@ -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[]
|
||||
|
||||
Reference in New Issue
Block a user