mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-29 01:14:41 +00:00
fixes #22523
There were 2 problems with the code in `sameType` for
`dcEqIgnoreDistinct`:
1. The code that skipped `{tyDistinct, tyGenericInst}` only ran if the
given types had different kinds. This is fixed by always performing this
skip.
2. The code block below that checks if `tyGenericInst`s have different
values still ran for `dcEqIgnoreDistinct` since it checks if the given
types are generic insts, not the skipped types (and also only the 1st
given type). This is fixed by only invoking this block for `dcEq`;
`dcEqOrDistinctOf` (which is unused) also skips the first given type.
Arguably there is another issue here that `skipGenericAlias` only ever
skips 1 type.
These combined fix the issue (`T` is `GenericInst(V, 1, distinct int)`
and `D[0]` is `GenericInst(D, 0, distinct int)`).
(cherry picked from commit b0e6d28782)
22 lines
366 B
Nim
22 lines
366 B
Nim
# issue #22523
|
|
|
|
from std/typetraits import distinctBase
|
|
|
|
type
|
|
V[p: static int] = distinct int
|
|
D[p: static int] = distinct int
|
|
T = V[1]
|
|
|
|
proc f(y: var T) = discard
|
|
|
|
var a: D[0]
|
|
|
|
static:
|
|
doAssert distinctBase(T) is distinctBase(D[0])
|
|
doAssert distinctBase(T) is int
|
|
doAssert distinctBase(D[0]) is int
|
|
doAssert T(a) is T
|
|
|
|
f(cast[ptr T](addr a)[])
|
|
f(T(a))
|