From 97fed258ed3287a17c6b798fd7ffe16508bd69d9 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Sat, 14 Feb 2026 05:59:21 +0800 Subject: [PATCH] fixes #25475; incompatible types errors for array types with different index types (#25505) fixes #25475 ```nim var x: array[0..1, int] = [0, 1] var y: array[4'u..5'u, int] = [0, 3] echo x == y ``` sigmatch treats array compatibility by element type + length, not by the index (range) type. Perhaps backend should do the same check --- compiler/sighashes.nim | 14 +++++++++++--- tests/array/tarray.nim | 14 ++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/compiler/sighashes.nim b/compiler/sighashes.nim index a4f1e00880..3b688920e4 100644 --- a/compiler/sighashes.nim +++ b/compiler/sighashes.nim @@ -41,6 +41,7 @@ type CoType CoOwnerSig CoIgnoreRange + CoIgnoreRangeInArray CoConsiderOwned CoDistinct CoHashTypeInsideNode @@ -220,10 +221,17 @@ proc hashType(c: var MD5Context, t: PType; flags: set[ConsiderFlag]; conf: Confi else: for a in t.kids: c.hashType a, flags+{CoIgnoreRange}, conf of tyRange: - if CoIgnoreRange notin flags: + if {CoIgnoreRange, CoIgnoreRangeInArray} * flags == {}: c &= char(t.kind) c.hashTree(t.n, {}, conf) - c.hashType(t.elementType, flags, conf) + c.hashType(t.elementType, flags, conf) + elif CoIgnoreRangeInArray in flags: + # include only the length of the range (not its specific bounds) + c &= char(t.kind) + let l = lengthOrd(conf, t) + lowlevel l + else: + c.hashType(t.elementType, flags, conf) of tyStatic: c &= char(t.kind) c.hashTree(t.n, {}, conf) @@ -253,7 +261,7 @@ proc hashType(c: var MD5Context, t: PType; flags: set[ConsiderFlag]; conf: Confi if tfVarargs in t.flags: c &= ".varargs" of tyArray: c &= char(t.kind) - c.hashType(t.indexType, flags-{CoIgnoreRange}, conf) + c.hashType(t.indexType, flags-{CoIgnoreRange}+{CoIgnoreRangeInArray}, conf) c.hashType(t.elementType, flags-{CoIgnoreRange}, conf) else: c &= char(t.kind) diff --git a/tests/array/tarray.nim b/tests/array/tarray.nim index e9f330e3be..301a6eff20 100644 --- a/tests/array/tarray.nim +++ b/tests/array/tarray.nim @@ -605,3 +605,17 @@ block t18643: except IndexDefect: caught = true doAssert caught, "IndexDefect not caught!" + + +# bug #25475 +block: + type N = object + b: seq[array[1'u, int]] + doAssert N(b: @[[0]]) == N(b: @[[0]]) + +block: + var x: array[5..6, int] = [0, 1] + var y: array[1..2, int] = [0, 1] + + doAssert x == y # compiles + doAssert @[x] == @[y]