t5643.nim 999 B

12345678910111213141516171819202122232425262728293031
  1. type
  2. Matrix*[M, N: static[int], T: SomeReal] = object
  3. data: ref array[N * M, T]
  4. Matrix64*[M, N: static[int]] = Matrix[M, N, float64]
  5. proc zeros64(M,N: static[int]): Matrix64[M,N] =
  6. new result.data
  7. for i in 0 .. < (M * N):
  8. result.data[i] = 0'f64
  9. proc bar*[M,N: static[int], T](a: Matrix[M,N,T], b: Matrix[M,N,T]) =
  10. discard
  11. let a = zeros64(2,2)
  12. bar(a,a)
  13. # https://github.com/nim-lang/Nim/issues/5643
  14. #
  15. # The test case was failing here, because the compiler failed to
  16. # detect the two matrix instantiations as the same type.
  17. #
  18. # The root cause was that the `T` type variable is a different
  19. # type after the first Matrix type has been matched.
  20. #
  21. # Sigmatch was failing to match the second version of `T`, but
  22. # due to some complex interplay between tyOr, tyTypeDesc and
  23. # tyGenericParam this was allowed to went through. The generic
  24. # instantiation of the second matrix was incomplete and the
  25. # generic cache lookup failed, producing two separate types.