Fix #25883 tuple sighash collision

This commit is contained in:
Mamy Ratsimbazafy
2026-06-09 12:59:59 +02:00
parent e942da94b5
commit 9f666494eb
2 changed files with 19 additions and 0 deletions

View File

@@ -211,6 +211,7 @@ proc hashType(c: var MD5Context, t: PType; flags: set[ConsiderFlag]; conf: Confi
c.hashTree(t.n, {}, conf)
of tyTuple:
c &= char(t.kind)
c &= t.len
if t.n != nil and CoType notin flags:
for i in 0..<t.n.len:
assert(t.n[i].kind == nkSym)

View File

@@ -0,0 +1,18 @@
discard """
output: "5"
"""
# bug #25883: C codegen assigns same type hash to tuples with different nesting
# but identical flattened content.
# ((Int[1], Int[2]), Int[13], Int[14]) and ((Int[1], Int[2], Int[13]), Int[14])
# must get distinct C type names.
type
Int[V: static int] = object
proc main() =
var b = ((1, 2), 13, 14)
var c = ((1, 2, 13), 14)
echo c[0][2]
main()