From 7309115d7729c62cc44db12c7c1a400cd7d4ac35 Mon Sep 17 00:00:00 2001 From: zerbina <100542850+zerbina@users.noreply.github.com> Date: Wed, 7 Aug 2024 23:06:00 +0200 Subject: [PATCH] fix wrong hooks being picked for tuple types (#1402) ## Summary * fix tuples such as `((A, B),)` and `((A,), B)` being assigned the the same set of hooks * fix the aforementioned tuples sharing the same RTTI object ## Details * add the tuple length to the type representation during type hashing (`sighash`), so that `((A,), B)` and `((A, B),)` result in two different `SigHash`es * `liftdestructors` uses `sighashes` for canonicalizing structural types, thus previously treating said tuples as the same type * RTTI creation, which also uses `SigHash`, was affected in the same way --- compiler/sem/sighashes.nim | 3 ++ .../ttuple_hook_synthesis_issue.nim | 30 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 tests/lang_objects/destructor/ttuple_hook_synthesis_issue.nim diff --git a/compiler/sem/sighashes.nim b/compiler/sem/sighashes.nim index e56fc615aed..152deff135f 100644 --- a/compiler/sem/sighashes.nim +++ b/compiler/sem/sighashes.nim @@ -188,6 +188,9 @@ proc hashType(c: var MD5Context, t: PType; flags: set[ConsiderFlag]) = c.hashTree(t.n, {}) of tyTuple: c &= char(t.kind) + # add the length so that (int, int) and ((int,), int) have different + # representations + c &= t.len if t.n != nil and CoType notin flags: assert(t.n.len == t.len) for i in 0..