diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index bdba34e36108e..8068cc5723643 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -841,6 +841,13 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet): Rope = # always call for sideeffects: assert t.kind != tyTuple discard getRecordDesc(m, t, result, check) + # 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 + addf(m.s[cfsTypes], "typedef $1 $2;$n", [result, typedefName]) + m.typeCache[sig] = typedefName + result = typedefName else: when false: if t.sym != nil and t.sym.name.s == "KeyValuePair": diff --git a/tests/statictypes/tstaticimportcpp.nim b/tests/statictypes/tstaticimportcpp.nim index e13cc36b453f4..0cbbc1df65c4c 100644 --- a/tests/statictypes/tstaticimportcpp.nim +++ b/tests/statictypes/tstaticimportcpp.nim @@ -1,9 +1,9 @@ discard """ targets: "cpp" -output: "[0, 0, 10, 0]\n5\n1.2\n15\ntest" +output: "[0, 0, 10, 0]\n5\n1.2\n15\ntest\n[0, 0, 20, 0]" """ -{.emit: """ +{.emit: """/*TYPESECTION*/ template struct GenericIntType { @@ -51,3 +51,9 @@ echo c.field echo d.field echo e.field +proc plus(a, b: GenInt4): GenInt4 = + for i in 0 ..< result.data.len: + result.data[i] = a.data[i] + b.data[i] + +echo plus(a, a).data +