fixes #26019; deepCopy should not be allowed for non-copyable type (#26030)

fixes #26019
This commit is contained in:
ringabout
2026-07-22 18:36:48 +08:00
committed by GitHub
parent adda34bcb8
commit 0cf1bc3835
3 changed files with 33 additions and 0 deletions

View File

@@ -3143,6 +3143,12 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
localError(p.config, e.info,
"for --mm:arc|atomicArc|orc 'deepcopy' support has to be enabled with --deepcopy:on")
let typ = e[1].typ.skipTypes({tyVar, tyRef, tyGenericInst, tyTypeDesc,
tyAlias, tyInferred, tySink, tyLent, tyOwned})
if hasDisabledAsgn(p.module.g.graph, typ):
localError(p.config, e.info,
"'deepCopy' is not available for type <" & typeToString(typ) & ">")
let x = if e[1].kind in {nkAddr, nkHiddenAddr}: e[1][0] else: e[1]
var a = initLocExpr(p, x)
var b = initLocExpr(p, e[2])

View File

@@ -0,0 +1,12 @@
discard """
matrix: "--mm:refc; --mm:orc --deepcopy:on"
errormsg: "'deepCopy' is not available for type <NoCopy>"
file: "system.nim"
"""
type NoCopy = object
proc `=copy`(a: var NoCopy; b: NoCopy) {.error.}
var a = new NoCopy
var b = deepCopy(a)

View File

@@ -0,0 +1,15 @@
discard """
matrix: "--mm:refc; --mm:orc --deepcopy:on"
errormsg: "'deepCopy' is not available for type <Container>"
file: "system.nim"
"""
type
NoCopy = object
Container = object
value: NoCopy
proc `=copy`(a: var NoCopy; b: NoCopy) {.error.}
var a = new Container
var b = deepCopy(a)