summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2014-12-31 01:55:13 +0100
committerAraq <rumpf_a@web.de>2014-12-31 01:55:13 +0100
commita93585e47fb41865a5315d83e78791c1349f945d (patch)
tree6b39e654ae7e8a50a5475d6cc62ff60f1586074c /tests
parent13b72ed0c025f540ac676dd229b781eb4ddee713 (diff)
parent595a8b628f48dfd29facf4d329d32ea5e7c6d9e7 (diff)
downloadNim-a93585e47fb41865a5315d83e78791c1349f945d.tar.gz
Merge branch 'devel' of https://github.com/Araq/Nim into devel
Diffstat (limited to 'tests')
-rw-r--r--tests/generics/t1789.nim44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/generics/t1789.nim b/tests/generics/t1789.nim
new file mode 100644
index 000000000..188db88f6
--- /dev/null
+++ b/tests/generics/t1789.nim
@@ -0,0 +1,44 @@
+discard """
+  output: "3\n0"
+"""
+
+# https://github.com/Araq/Nim/issues/1789
+
+type
+  Foo[N: static[int]] = object
+
+proc bindStaticN[N](foo: Foo[N]) =
+  var ar0: array[3, int]
+  var ar1: array[N, int]
+  var ar2: array[1..N, int]
+  var ar3: array[0..(N+10), float]
+  echo N
+
+var f: Foo[3]
+f.bindStaticN
+
+# case 2
+
+type
+  ObjectWithStatic[X, Y: static[int], T] = object
+    bar: array[X * Y, T]   # this one works
+
+  AliasWithStatic[X, Y: static[int], T] = array[X * Y, T]
+
+var
+  x: ObjectWithStatic[1, 2, int]
+  y: AliasWithStatic[2, 3, int]
+
+# case 3
+
+type
+  Bar[N: static[int], T] = object
+    bar: array[N, T]
+
+proc `[]`*[N, T](f: Bar[N, T], n: range[0..(N - 1)]): T =
+  assert high(n) == N-1
+  result = f.bar[n]
+  
+var b: Bar[3, int]
+echo b[2]
+