relax the parameter of ensureMove; allow let statements (#22466)

* relax the parameter of `ensureMove`; allow let statements

* fixes the test

(cherry picked from commit 4c89223171)
This commit is contained in:
ringabout
2023-08-12 19:23:54 +08:00
committed by narimiran
parent 3fa378533a
commit c3425c05e9
3 changed files with 6 additions and 4 deletions

View File

@@ -668,7 +668,8 @@ proc magicsAfterOverloadResolution(c: PContext, n: PNode,
result.typ = expectedType # type inference for empty sequence # bug #21377
of mEnsureMove:
result = n
if isAssignable(c, n[1]) notin {arLValue, arLocalLValue}:
localError(c.config, n.info, "'" & $n[1] & "'" & " is not a mutable location; it cannot be moved")
if n[1].kind in {nkStmtListExpr, nkBlockExpr,
nkIfExpr, nkCaseStmt, nkTryStmt}:
localError(c.config, n.info, "Nested expressions cannot be moved: '" & $n[1] & "'")
else:
result = n

View File

@@ -20,7 +20,8 @@ block:
discard x.s
proc main =
var x = X(s: "abcdefg")
let m = "abcdefg"
var x = X(s: ensureMove m)
consume(ensureMove x)
static: main()

View File

@@ -1,5 +1,5 @@
discard """
errormsg: "'if true: s else: String()' is not a mutable location; it cannot be moved"
errormsg: "Nested expressions cannot be moved: 'if true: s else: String()'"
"""
type