Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion compiler/jsgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1586,7 +1586,11 @@ proc genAddr(p: PProc, n: PNode, r: var TCompRes) =
of nkObjDownConv:
gen(p, n[0], r)
of nkHiddenDeref, nkDerefExpr:
gen(p, n[0], r)
if n.kind in {nkAddr, nkHiddenAddr}:
# addr ( deref ( x )) --> x
gen(p, n[0][0], r)
else:
gen(p, n[0], r)
of nkHiddenAddr:
gen(p, n[0], r)
of nkConv:
Expand Down
3 changes: 1 addition & 2 deletions compiler/transf.nim
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,7 @@ proc transformAddrDeref(c: PTransf, n: PNode, kinds: TNodeKinds, isAddr = false)
n.typ.kind == tyVar and
n.typ.skipTypes(abstractVar).kind == tyOpenArray and
n[0][0].typ.skipTypes(abstractVar).kind == tyString) and
not (isAddr and n.typ.kind == tyVar and n[0][0].typ.kind == tyRef and
n[0][0].kind == nkObjConstr)
not (isAddr and n.typ.kind == tyVar and n[0][0].typ.kind == tyRef)
: # elimination is harmful to `for tuple unpack` because of newTupleAccess
# it is also harmful to openArrayLoc (var openArray) for strings
# addr ( deref ( x )) --> x
Expand Down
22 changes: 22 additions & 0 deletions tests/vm/tmisc_vm.nim
Original file line number Diff line number Diff line change
Expand Up @@ -457,3 +457,25 @@ proc publish*(): void {.transform.} =
map["k"].incl "d"

publish()


iterator it(x: var int): var int =
yield x

proc it(x: var int): var int =
x

proc xxx() =
type Obj = object
field: ref int
var obj = Obj(field: new(int))
obj.field[] = 123
assert it(obj.field[]) == 123 # fails
for x in it(obj.field[]): # fails
assert x == 123

static:
xxx()

xxx()