summary refs log tree commit diff stats
path: root/tests/run
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2012-08-06 18:11:03 +0200
committerAraq <rumpf_a@web.de>2012-08-06 18:11:03 +0200
commitce23b814a0255a1a20eefff5e9b3679d52b8aa43 (patch)
tree7cf5ee8f11d53cd7aa45cebb4e8bbdbb3e6545bf /tests/run
parent5cd933a44d37b46dd3a1f349777efca6eaaf11e2 (diff)
downloadNim-ce23b814a0255a1a20eefff5e9b3679d52b8aa43.tar.gz
borrow works with generics
Diffstat (limited to 'tests/run')
-rw-r--r--tests/run/tborrow.nim21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/run/tborrow.nim b/tests/run/tborrow.nim
new file mode 100644
index 000000000..8e6aeba74
--- /dev/null
+++ b/tests/run/tborrow.nim
@@ -0,0 +1,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