tbind.nim 1021 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. discard """
  2. output: '''
  3. 3
  4. 1
  5. 1
  6. 1
  7. '''
  8. """
  9. block tbind:
  10. # Test the new ``bind`` keyword for templates
  11. proc p1(x: int8, y: int): int = return x + y
  12. template tempBind(x, y): untyped =
  13. bind p1
  14. p1(x, y)
  15. proc p1(x: int, y: int8): int = return x - y
  16. # This is tricky: the call to ``p1(1'i8, 2'i8)`` should not fail in line 6,
  17. # because it is not ambiguous there. But it is ambiguous after line 8.
  18. echo tempBind(1'i8, 2'i8) #OUT 3
  19. import mbind3
  20. echo genId() #OUT 1
  21. import strtabs
  22. block tbinoverload:
  23. template t() =
  24. block:
  25. bind newStringTable
  26. discard {"Content-Type": "text/html"}.newStringTable()
  27. discard {:}.newStringTable
  28. #discard {"Content-Type": "text/html"}.newStringTable()
  29. t()
  30. block tmixin:
  31. type
  32. TFoo1 = object of RootObj
  33. v: int
  34. TFoo2 = object of TFoo1
  35. v2: int
  36. proc test(f: TFoo1) =
  37. echo "1"
  38. proc Foo[T](f: T) =
  39. mixin test
  40. test(f)
  41. var
  42. a: TFoo1
  43. b: TFoo2
  44. proc test(f: TFoo2) =
  45. echo "2"
  46. Foo(a)
  47. Foo(b)