mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-14 15:43:45 +00:00
Fix #25883 tuple sighash collision
This commit is contained in:
@@ -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)
|
||||
|
||||
18
tests/ccgbugs2/t25883_tuple_sighash_collision.nim
Normal file
18
tests/ccgbugs2/t25883_tuple_sighash_collision.nim
Normal 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()
|
||||
Reference in New Issue
Block a user