tborrow.nim 430 B

12345678910111213141516171819202122
  1. discard """
  2. output: "4887 true"
  3. """
  4. # test the new borrow feature that works with generics:
  5. proc `++`*[T: int | float](a, b: T): T =
  6. result = a + b
  7. type
  8. DI = distinct int
  9. DF = distinct float
  10. DS = distinct string
  11. proc `++`(x, y: DI): DI {.borrow.}
  12. proc `++`(x, y: DF): DF {.borrow.}
  13. proc `$`(x: DI): string {.borrow.}
  14. proc `$`(x: DF): string {.borrow.}
  15. echo 4544.DI ++ 343.DI, " ", (4.5.DF ++ 0.5.DF).float == 5.0