Skip to content

Commit 6adeec8

Browse files
authored
fixes ensureMove can't move calls with var types (#1215)
`[]` is a call that returns a var type, so a `deref` is needed. `(deref (call [] x))` should be moveable
1 parent 97ce90f commit 6adeec8

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/hexer/duplifier.nim

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ proc constructsValue*(n: Cursor): bool =
9393
of CastX, ConvX, HconvX, DconvX:
9494
inc n
9595
skip n
96+
of DerefX, HDerefX:
97+
inc n
9698
of BaseobjX:
9799
inc n
98100
skip n
@@ -846,7 +848,7 @@ proc trEnsureMove(c: var Context; n: var Cursor; e: Expects) =
846848
tr c, n, e
847849
skipParRi n
848850
else:
849-
let m = "not the last usage of: " & asNimCode(n)
851+
let m = "not the last usage of: " & asNimCode(arg)
850852
c.dest.buildTree ErrT, info:
851853
c.dest.addSubtree n
852854
c.dest.add strToken(pool.strings.getOrIncl(m), info)

tests/nimony/arc/tensuremove.nim

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,14 @@ block:
148148
assert y == 1
149149
foo()
150150

151-
# TODO:
152-
# block:
153-
# proc foo =
154-
# var x = @[1, 2, 3]
155-
# let y = ensureMove x[0] # move
156-
# assert y == 1
157-
# # when not defined(js):
158-
# # assert x == @[0, 2, 3]
159-
# foo()
151+
block:
152+
proc foo =
153+
var x = @[1, 2, 3]
154+
let y = ensureMove x[0] # move
155+
assert y == 1
156+
# when not defined(js):
157+
# assert x == @[0, 2, 3]
158+
foo()
160159

161160
block:
162161
proc foo =
@@ -167,11 +166,10 @@ block:
167166
# assert x == @[0, 2, 3]
168167
foo()
169168

170-
# TODO:
171-
# block:
172-
# proc foo =
173-
# var x = @["1", "2", "3"]
174-
# let y = ensureMove x[0] # move
175-
# assert y == "1"
176-
# foo()
169+
block:
170+
proc foo =
171+
var x = @["1", "2", "3"]
172+
let y = ensureMove x[0] # move
173+
assert y == "1"
174+
foo()
177175

0 commit comments

Comments
 (0)