fixes #24754; {.gcsafe.} block breaks move analysis (#24757)

fixes #24754

(cherry picked from commit a7711d452d)
This commit is contained in:
ringabout
2025-03-11 16:59:55 +08:00
committed by narimiran
parent ae8ae8fa95
commit 8f563f2cc9
2 changed files with 15 additions and 1 deletions

View File

@@ -1164,7 +1164,7 @@ proc moveOrCopy(dest, ri: PNode; c: var Con; s: var Scope, flags: set[MoveOrCopy
c.finishCopy(result, dest, flags, isFromSink = false)
of nkHiddenSubConv, nkHiddenStdConv, nkConv, nkObjDownConv, nkObjUpConv, nkCast:
result = c.genSink(s, dest, p(ri, c, s, sinkArg), flags)
of nkStmtListExpr, nkBlockExpr, nkIfExpr, nkCaseStmt, nkTryStmt:
of nkStmtListExpr, nkBlockExpr, nkIfExpr, nkCaseStmt, nkTryStmt, nkPragmaBlock:
template process(child, s): untyped = moveOrCopy(dest, child, c, s, flags)
# We know the result will be a stmt so we use that fact to optimize
handleNestedTempl(ri, process, willProduceStmt = true)

View File

@@ -882,3 +882,17 @@ proc test_18070() = # bug #18070
doAssert msg == "", "expected empty string but got: " & $msg
test_18070()
block: # bug #24754
type NoCopy = object
id: int
proc `=copy`(a: var NoCopy, b: NoCopy) {.error.}
proc foo(): NoCopy =
{.gcsafe.}:
let s = 12
NoCopy(id: s)
doAssert foo().id == 12