diff options
author | ringabout <43030857+ringabout@users.noreply.github.com> | 2024-08-11 16:12:48 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-11 10:12:48 +0200 |
commit | 1d59e1cbb6521d1c5c9a634dbd6bcbcbc8ae1cd4 (patch) | |
tree | 62a9dc8d613fc00f44436573aa2b0764323b0815 | |
parent | 2a2474d395afb58ef71897530ff334f4725514b4 (diff) | |
download | Nim-1d59e1cbb6521d1c5c9a634dbd6bcbcbc8ae1cd4.tar.gz |
fixes #23907; Double destroy using proc type alias with a sink (#23909)
fixes #23907
-rw-r--r-- | compiler/injectdestructors.nim | 3 | ||||
-rw-r--r-- | tests/arc/tarcmisc.nim | 23 |
2 files changed, 25 insertions, 1 deletions
diff --git a/compiler/injectdestructors.nim b/compiler/injectdestructors.nim index d641b11e6..92c823f37 100644 --- a/compiler/injectdestructors.nim +++ b/compiler/injectdestructors.nim @@ -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: diff --git a/tests/arc/tarcmisc.nim b/tests/arc/tarcmisc.nim index 88582303d..58b4aa7c0 100644 --- a/tests/arc/tarcmisc.nim +++ b/tests/arc/tarcmisc.nim @@ -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 + |