diff options
author | Bung <crc32@qq.com> | 2022-10-21 15:28:18 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-21 09:28:18 +0200 |
commit | 84fab7f39bd89ef6e9c3e104a17af8d9f049d8e6 (patch) | |
tree | d67b244e4e0f08a15d996ac261bd74f5426c3e45 | |
parent | 04c48e3c5b7a98b065d9f3a96575a304a60a9290 (diff) | |
download | Nim-84fab7f39bd89ef6e9c3e104a17af8d9f049d8e6.tar.gz |
fix #19349 incompatible type when mixing float32 and cfloat in generics (#20551)
-rw-r--r-- | compiler/types.nim | 3 | ||||
-rw-r--r-- | tests/alias/t19349.nim | 19 |
2 files changed, 21 insertions, 1 deletions
diff --git a/compiler/types.nim b/compiler/types.nim index 44cbf7ae1..b78461769 100644 --- a/compiler/types.nim +++ b/compiler/types.nim @@ -1149,13 +1149,14 @@ proc sameTypeAux(x, y: PType, c: var TSameTypeClosure): bool = of tyEmpty, tyChar, tyBool, tyNil, tyPointer, tyString, tyCstring, tyInt..tyUInt64, tyTyped, tyUntyped, tyVoid: result = sameFlags(a, b) - if result and PickyCAliases in c.flags: + if result and {PickyCAliases, ExactTypeDescValues} <= c.flags: # additional requirement for the caching of generics for importc'ed types: # the symbols must be identical too: let symFlagsA = if a.sym != nil: a.sym.flags else: {} let symFlagsB = if b.sym != nil: b.sym.flags else: {} if (symFlagsA+symFlagsB) * {sfImportc, sfExportc} != {}: result = symFlagsA == symFlagsB + of tyStatic, tyFromExpr: result = exprStructuralEquivalent(a.n, b.n) and sameFlags(a, b) if result and a.len == b.len and a.len == 1: diff --git a/tests/alias/t19349.nim b/tests/alias/t19349.nim new file mode 100644 index 000000000..1e1e58264 --- /dev/null +++ b/tests/alias/t19349.nim @@ -0,0 +1,19 @@ +discard """ + action: "compile" +""" + +type + Vec3[T: SomeNumber] = object + arr: array[3, T] + +var + cfloatArr: array[3, array[3, cfloat]] + cfloatSeq = newSeq[Vec3[cfloat]]() +for row in cfloatArr: + cfloatSeq.add(Vec3[float32](arr: [row[0], row[1], row[2]])) + +var + cuintArr: array[3, array[3, cuint]] + cuintSeq = newSeq[Vec3[cuint]]() +for row in cuintArr: + cuintSeq.add(Vec3[uint32](arr: [row[0], row[1], row[2]])) |