diff options
author | metagn <metagngn@gmail.com> | 2024-07-20 01:02:08 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-20 09:02:08 +0200 |
commit | 31ee75f10e6482cd482d329507190ac850eee2cf (patch) | |
tree | 9c3908d9d9ba53f68a8b6a8faacf36a7e683dc7c /tests | |
parent | 2f5cfd68298868cabcbc20967aa35bc708d507a8 (diff) | |
download | Nim-31ee75f10e6482cd482d329507190ac850eee2cf.tar.gz |
bypass constraints for tyFromExpr in generic bodies (#23863)
fixes #19819, fixes #23339 Since #22029 `tyFromExpr` does not match anything in overloading, so generic bodies can know which call expressions to delay until the type can be evaluated. However generic type invocations also run overloading to check for generic constraints even in generic bodies. To prevent them from failing early from the overload not matching, pretend that `tyFromExpr` matches. This mirrors the behavior of the compiler in more basic cases like: ```nim type Foo[T: int] = object x: T Bar[T] = object y: Foo[T] ``` Unfortunately this case doesn't respect the constraint (#21181, some other bugs) but `tyFromExpr` should easily use the same principle when it does.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/generics/tuninstantiatedgenericcalls.nim | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/generics/tuninstantiatedgenericcalls.nim b/tests/generics/tuninstantiatedgenericcalls.nim index 63ba3908f..2163789e7 100644 --- a/tests/generics/tuninstantiatedgenericcalls.nim +++ b/tests/generics/tuninstantiatedgenericcalls.nim @@ -145,3 +145,21 @@ block: # issue #23730 proc test(M: static[int]): array[1 shl M, int] = discard doAssert len(test(3)) == 8 doAssert len(test(5)) == 32 + +block: # issue #19819 + type + Example[N: static int] = distinct int + What[E: Example] = Example[E.N + E.N] + +block: # issue #23339 + type + A = object + B = object + template aToB(t: typedesc[A]): typedesc = B + type + Inner[I] = object + innerField: I + Outer[O] = object + outerField: Inner[O.aToB] + var x: Outer[A] + doAssert typeof(x.outerField.innerField) is B |