diff options
author | Zahary Karadjov <zahary@gmail.com> | 2017-04-08 17:57:02 +0300 |
---|---|---|
committer | Zahary Karadjov <zahary@gmail.com> | 2017-04-08 23:42:42 +0300 |
commit | 03172bef6f58a2176c08253de44339ad9fce15d5 (patch) | |
tree | 02d09811292caa7826f8b340f986f60b96f9db9d /tests | |
parent | e9a3ffbc3d318911da5c46582a70288dd16275f3 (diff) | |
download | Nim-03172bef6f58a2176c08253de44339ad9fce15d5.tar.gz |
fix #5643; fix #5644
Diffstat (limited to 'tests')
-rw-r--r-- | tests/generics/t5643.nim | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/generics/t5643.nim b/tests/generics/t5643.nim new file mode 100644 index 000000000..962d5cef5 --- /dev/null +++ b/tests/generics/t5643.nim @@ -0,0 +1,30 @@ +type + Matrix*[M, N: static[int], T: SomeReal] = object + data: ref array[N * M, T] + + Matrix64*[M, N: static[int]] = Matrix[M, N, float64] + +proc zeros64(M,N: static[int]): Matrix64[M,N] = + new result.data + for i in 0 .. < (M * N): + result.data[i] = 0'f64 + +proc bar*[M,N: static[int], T](a: Matrix[M,N,T], b: Matrix[M,N,T]) = + discard + +let a = zeros64(2,2) +bar(a,a) + # https://github.com/nim-lang/Nim/issues/5643 + # + # The test case was failing here, because the compiler failed to + # detect the two matrix instantiations as the same type. + # + # The root cause was that the `T` type variable is a different + # type after the first Matrix type has been matched. + # + # Sigmatch was failing to match the second version of `T`, but + # due to some complex interplay between tyOr, tyTypeDesc and + # tyGenericParam this was allowed to went through. The generic + # instantiation of the second matrix was incomplete and the + # generic cache lookup failed, producing two separate types. + |