tbind_for_generics.nim 279 B

123456789101112131415161718
  1. discard """
  2. errormsg: "type mismatch: got <Foo, Foo>"
  3. line: 8
  4. """
  5. proc g[T](x: T) =
  6. bind `+`
  7. # because we bind `+` here, we must not find the `+` for 'Foo' below:
  8. echo x + x
  9. type
  10. Foo = object
  11. a: int
  12. proc `+`(a, b: Foo): Foo = Foo(a: a.a+b.a)
  13. g(3)
  14. g(Foo(a: 8))