Files
Nim/tests/overload/tgenericalias.nim
metagn 45b8434c7d skip tyAlias in generic alias checks [backport:2.0] (#24417)
fixes #24415

Since #23978 (which is in 2.0), all generic types that alias to another
type now insert a `tyAlias` layer in their value. However the
`skipGenericAlias` etc code which `sigmatch` uses is not updated for
this, so `tyAlias` is now skipped in these.

The relevant code in sigmatch is:
67ad1ae159/compiler/sigmatch.nim (L1668-L1673)

This behavior is also suspicious IMO, not skipping a structural
`tyGenericInst` alias can be useful for code like #10220, but this is
currently arbitrarily decided based on "depth" and whether the alias is
to another `tyGenericInst` type or not. Maybe in the future we could
enforce the use of a nominal type.
2024-11-08 08:36:52 +01:00

23 lines
550 B
Nim

block: # issue #13799
type
X[A, B] = object
a: A
b: B
Y[A] = X[A, int]
template s(T: type X): X = T()
template t[A, B](T: type X[A, B]): X[A, B] = T()
proc works1(): Y[int] = s(X[int, int])
proc works2(): Y[int] = t(X[int, int])
proc works3(): Y[int] = t(Y[int])
proc broken(): Y[int] = s(Y[int])
block: # issue #24415
type GVec2[T] = object
x, y: T
type Uniform[T] = T
proc foo(v: Uniform[GVec2[float32]]): float32 =
result = v.x
let f = GVec2[float32](x: 1.0f, y: 2.0f)
doAssert foo(f) == 1.0f