fix #12946 Bad C++ codegen on distinct generics C++ types (#21157)

This commit is contained in:
Bung
2022-12-23 16:47:01 +08:00
committed by GitHub
parent 3bba2b34fd
commit 13251c2ac9
2 changed files with 9 additions and 4 deletions

View File

@@ -826,7 +826,8 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet; kind: TSymKin
m.s[cfsTypes].addf("typedef $1 $2[$3];$n",
[foo, result, rope(n)])
of tyObject, tyTuple:
if isImportedCppType(t) and origTyp.kind == tyGenericInst:
let tt = origTyp.skipTypes({tyDistinct})
if isImportedCppType(t) and tt.kind == tyGenericInst:
let cppNameAsRope = getTypeName(m, t, sig)
let cppName = $cppNameAsRope
var i = 0
@@ -849,7 +850,7 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet; kind: TSymKin
result.add cppName.substr(chunkStart, chunkEnd)
chunkStart = i
let typeInSlot = resolveStarsInCppType(origTyp, idx + 1, stars)
let typeInSlot = resolveStarsInCppType(tt, idx + 1, stars)
addResultType(typeInSlot)
else:
inc i
@@ -858,9 +859,9 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet; kind: TSymKin
result.add cppName.substr(chunkStart)
else:
result = cppNameAsRope & "<"
for i in 1..<origTyp.len-1:
for i in 1..<tt.len-1:
if i > 1: result.add(" COMMA ")
addResultType(origTyp[i])
addResultType(tt[i])
result.add("> ")
# always call for sideeffects:
assert t.kind != tyTuple

4
tests/cpp/t12946.nim Normal file
View File

@@ -0,0 +1,4 @@
import std/atomics
type Futex = distinct Atomic[int32]
var x: Futex