summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/semmagic.nim5
-rw-r--r--tests/system/tensuremove.nim3
-rw-r--r--tests/system/tensuremove2.nim2
3 files changed, 6 insertions, 4 deletions
diff --git a/compiler/semmagic.nim b/compiler/semmagic.nim
index bee2a983e..d06b32e47 100644
--- a/compiler/semmagic.nim
+++ b/compiler/semmagic.nim
@@ -667,7 +667,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
diff --git a/tests/system/tensuremove.nim b/tests/system/tensuremove.nim
index 980f2ea58..52d9a43a8 100644
--- a/tests/system/tensuremove.nim
+++ b/tests/system/tensuremove.nim
@@ -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()
diff --git a/tests/system/tensuremove2.nim b/tests/system/tensuremove2.nim
index 1fcbc1c0f..39bbeb22e 100644
--- a/tests/system/tensuremove2.nim
+++ b/tests/system/tensuremove2.nim
@@ -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