summary refs log tree commit diff stats
path: root/tests/borrow/tborrow.nim
blob: 8e6aeba749f18a680af6f3a03564a62accb551b4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
discard """
  output: "4887 true"
"""

# test the new borrow feature that works with generics:

proc `++`*[T: int | float](a, b: T): T =
  result = a + b
  
type
  DI = distinct int
  DF = distinct float
  DS = distinct string
  
proc `++`(x, y: DI): DI {.borrow.}
proc `++`(x, y: DF): DF {.borrow.}

proc `$`(x: DI): string {.borrow.}
proc `$`(x: DF): string {.borrow.}

echo  4544.DI ++ 343.di, " ", (4.5.df ++ 0.5.df).float == 5.0