fixes #22218; avoids cursor when copy is disabled (#23209)

fixes #22218
This commit is contained in:
ringabout
2024-01-19 04:47:13 +08:00
committed by GitHub
parent 3fb46fac32
commit b2f79df81c
2 changed files with 28 additions and 1 deletions

25
tests/arc/t22218.nim Normal file
View File

@@ -0,0 +1,25 @@
discard """
cmd: "nim c --mm:arc $file"
errormsg: "'=copy' is not available for type <Obj>; requires a copy because it's not the last read of 'chan[]'; routine: test"
"""
# bug #22218
type Obj[T] = object
v: T
proc `=copy`[T](
dest: var Obj[T],
source: Obj[T]
) {.error: "A channel cannot be copied".}
from system/ansi_c import c_calloc
proc test() =
var v: bool = true
var chan = cast[ptr Obj[int]](c_calloc(1, csize_t sizeof(Obj[int])))
var copy = chan[]
echo chan.v
echo v
test()