From 2fc23370ecae4cedd7b6038e839ed2cea47792ee Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Mon, 15 Sep 2025 21:03:22 +0800 Subject: [PATCH] fixes #24844; Invalid C codegen refc with generic types containing gc memory (#25160) fixes #24844 it may not be used in other places except in `genTraverseProc`, we have to generate a `typedesc` for this case, not a weak `typedec` (cherry picked from commit a77d1cc6c1f69a8b50034bc8a8023e976263b2f4) --- compiler/ccgtypes.nim | 3 +++ tests/refc/m24844.nim | 8 ++++++++ tests/refc/t24844.nim | 11 +++++++++++ 3 files changed, 22 insertions(+) create mode 100644 tests/refc/m24844.nim create mode 100644 tests/refc/t24844.nim diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index eb1e46c460..989610d207 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -1886,6 +1886,9 @@ proc genTypeInfoV1(m: BModule; t: PType; info: TLineInfo): Rope = of tyRef: genTypeInfoAux(m, t, t, result, info) if m.config.selectedGC in {gcMarkAndSweep, gcRefc, gcGo}: + # it may not be used in other places except in `genTraverseProc`, + # we have to generate a typedesc for this case, not a weak one + discard getTypeDesc(m, origType.last) let markerProc = genTraverseProc(m, origType, sig) m.s[cfsTypeInit3].addf("$1.marker = $2;$n", [tiNameForHcr(m, result), markerProc]) of tyPtr, tyRange, tyUncheckedArray: genTypeInfoAux(m, t, t, result, info) diff --git a/tests/refc/m24844.nim b/tests/refc/m24844.nim new file mode 100644 index 0000000000..59e709d24d --- /dev/null +++ b/tests/refc/m24844.nim @@ -0,0 +1,8 @@ +type + S*[T] = ref object of RootObj + k: string + A*[T] = ref object of S[T] + +proc p*[T](): S[T] = S[T]() +proc u*() = discard A[int]() +discard A[int]() \ No newline at end of file diff --git a/tests/refc/t24844.nim b/tests/refc/t24844.nim new file mode 100644 index 0000000000..1a60e94125 --- /dev/null +++ b/tests/refc/t24844.nim @@ -0,0 +1,11 @@ +discard """ + matrix: "--mm:refc; --mm:arc" + joinable: false +""" + +import m24844 + +u() + +type E = distinct int +discard p[E]() \ No newline at end of file