ttemplateparamcall.nim 693 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. discard """
  2. output: '''
  3. L
  4. L
  5. L
  6. L
  7. B
  8. B
  9. B
  10. B
  11. '''
  12. """
  13. # issue #18202
  14. type
  15. R = object
  16. S = object
  17. U = R | S
  18. L = object
  19. B = object
  20. C = B | L
  21. proc f(n: L, q: R | S) = echo "L"
  22. proc f(n: B, q: R | S) = echo "B"
  23. proc g(n: C, q: R | S) = echo (when n is L: "L" else: "B")
  24. proc h(n: L, q: U) = echo "L"
  25. proc h(n: B, q: U) = echo "B"
  26. proc j(n: C, q: U) = echo (when n is L: "L" else: "B")
  27. proc e(n: B | L, a: R) =
  28. template t(operations: untyped, fn: untyped) = fn(n, operations)
  29. # Work as expected
  30. t(a, f)
  31. t(a, g)
  32. t(a, j)
  33. # Error: type mismatch: got <R, proc [*missing parameters*](n: B, q: U) | proc [*missing parameters*](n: L, q: U)>
  34. t(a, h)
  35. e(L(), R())
  36. e(B(), R())