Skip to content

Commit c5d62bc

Browse files
bung87narimiran
authored andcommitted
fix #19349 incompatible type when mixing float32 and cfloat in generics (#20551)
(cherry picked from commit 84fab7f)
1 parent 8e04112 commit c5d62bc

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

compiler/types.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1145,13 +1145,14 @@ proc sameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
11451145
of tyEmpty, tyChar, tyBool, tyNil, tyPointer, tyString, tyCstring,
11461146
tyInt..tyUInt64, tyTyped, tyUntyped, tyVoid:
11471147
result = sameFlags(a, b)
1148-
if result and PickyCAliases in c.flags:
1148+
if result and {PickyCAliases, ExactTypeDescValues} <= c.flags:
11491149
# additional requirement for the caching of generics for importc'ed types:
11501150
# the symbols must be identical too:
11511151
let symFlagsA = if a.sym != nil: a.sym.flags else: {}
11521152
let symFlagsB = if b.sym != nil: b.sym.flags else: {}
11531153
if (symFlagsA+symFlagsB) * {sfImportc, sfExportc} != {}:
11541154
result = symFlagsA == symFlagsB
1155+
11551156
of tyStatic, tyFromExpr:
11561157
result = exprStructuralEquivalent(a.n, b.n) and sameFlags(a, b)
11571158
if result and a.len == b.len and a.len == 1:

tests/alias/t19349.nim

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
discard """
2+
action: "compile"
3+
"""
4+
5+
type
6+
Vec3[T: SomeNumber] = object
7+
arr: array[3, T]
8+
9+
var
10+
cfloatArr: array[3, array[3, cfloat]]
11+
cfloatSeq = newSeq[Vec3[cfloat]]()
12+
for row in cfloatArr:
13+
cfloatSeq.add(Vec3[float32](arr: [row[0], row[1], row[2]]))
14+
15+
var
16+
cuintArr: array[3, array[3, cuint]]
17+
cuintSeq = newSeq[Vec3[cuint]]()
18+
for row in cuintArr:
19+
cuintSeq.add(Vec3[uint32](arr: [row[0], row[1], row[2]]))

0 commit comments

Comments
 (0)