fixes #23907; Double destroy using proc type alias with a sink (#23909)

fixes #23907
This commit is contained in:
ringabout
2024-08-11 16:12:48 +08:00
committed by GitHub
parent 2a2474d395
commit 1d59e1cbb6
2 changed files with 25 additions and 1 deletions

View File

@@ -894,7 +894,8 @@ proc p(n: PNode; c: var Con; s: var Scope; mode: ProcessMode; tmpFlags = {sfSing
elif c.inSpawn > 0:
c.inSpawn.dec
let parameters = n[0].typ
# bug #23907; skips tyGenericInst for generic callbacks
let parameters = if n[0].typ != nil: n[0].typ.skipTypes(abstractInst) else: n[0].typ
let L = if parameters != nil: parameters.signatureLen else: 0
when false:

View File

@@ -766,3 +766,26 @@ block: # bug #23524
doAssert t2.a == 100
main()
block: # bug #23907
type
Thingy = object
value: int
ExecProc[C] = proc(value: sink C): int {.nimcall.}
proc `=copy`(a: var Thingy, b: Thingy) {.error.}
var thingyDestroyCount = 0
proc `=destroy`(thingy: Thingy) =
assert(thingyDestroyCount <= 0)
thingyDestroyCount += 1
proc store(value: sink Thingy): int =
result = value.value
let callback: ExecProc[Thingy] = store
doAssert callback(Thingy(value: 123)) == 123