mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-21 14:55:24 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user