summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorZahary Karadjov <zahary@gmail.com>2017-06-10 18:11:31 +0300
committerAndreas Rumpf <rumpf_a@web.de>2017-06-20 11:29:42 +0200
commit491162d3c8d7ac99ba02fdc2b511a31057ec7a55 (patch)
tree429a267322036c87f18d645b0c2667c2cc7fe768 /tests
parent9edf66df85dcd59e97026ea4273f9e8e5fee6cc5 (diff)
downloadNim-491162d3c8d7ac99ba02fdc2b511a31057ec7a55.tar.gz
close #5106
Diffstat (limited to 'tests')
-rw-r--r--tests/generics/tfakedependenttypes.nim61
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/generics/tfakedependenttypes.nim b/tests/generics/tfakedependenttypes.nim
new file mode 100644
index 000000000..cd4be806c
--- /dev/null
+++ b/tests/generics/tfakedependenttypes.nim
@@ -0,0 +1,61 @@
+discard """
+output: '''
+U[3]
+U[(f: 3)]
+U[[3]]
+'''
+"""
+
+# https://github.com/nim-lang/Nim/issues/5106
+
+import typetraits
+
+block:
+  type T = distinct int
+
+  proc `+`(a, b: T): T =
+    T(int(a) + int(b))
+
+  type U[F: static[T]] = distinct int
+
+  proc `+`[P1, P2: static[T]](a: U[P1], b: U[P2]): U[P1 + P2] =
+    U[P1 + P2](int(a) + int(b))
+
+  var a = U[T(1)](1)
+  var b = U[T(2)](2)
+  var c = a + b
+  echo c.type.name
+  
+block:
+  type T = object
+    f: int
+
+  proc `+`(a, b: T): T =
+    T(f: a.f + b.f)
+
+  type U[F: static[T]] = distinct int
+
+  proc `+`[P1, P2: static[T]](a: U[P1], b: U[P2]): U[P1 + P2] =
+    U[P1 + P2](int(a) + int(b))
+
+  var a = U[T(f: 1)](1)
+  var b = U[T(f: 2)](2)
+  var c = a + b
+  echo c.type.name
+
+block:
+  type T = distinct array[0..0, int]
+
+  proc `+`(a, b: T): T =
+    T([array[0..0, int](a)[0] + array[0..0, int](b)[0]])
+
+  type U[F: static[T]] = distinct int
+
+  proc `+`[P1, P2: static[T]](a: U[P1], b: U[P2]): U[P1 + P2] =
+    U[P1 + P2](int(a) + int(b))
+
+  var a = U[T([1])](1)
+  var b = U[T([2])](2)
+  var c = a + b
+  echo c.type.name
+