From 657b950478cc3a229b2998350c6728c15311b49f Mon Sep 17 00:00:00 2001 From: jmgomez Date: Sat, 10 Aug 2024 10:42:55 +0100 Subject: [PATCH] Fixes an issue where two types can collide in the cgen When generating a header with `--header` and then using it from another Nim project to import the generated types, generic instances can collide and produce an error i.e. `typedef MyGeneric[TypeA] typename` `typedef MyGeneric[TypeB] typename` `signature` here cant be the same as they are different types. This issue can be avoided by using the Nim type as part of the name which is what PR does. --- compiler/ccgtypes.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index 5fc4d655214f8..424855a7289a7 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -1114,7 +1114,7 @@ proc getTypeDescAux(m: BModule; origTyp: PType, check: var IntSet; kind: TypeDes # The resulting type will include commas and these won't play well # with the C macros for defining procs such as N_NIMCALL. We must # create a typedef for the type and use it in the proc signature: - let typedefName = "TY" & $sig + let typedefName = "TY$1_$2" % [$sig, m.encodeType(origTyp)] m.s[cfsTypes].addf("typedef $1 $2;$n", [result, typedefName]) m.typeCache[sig] = typedefName result = typedefName