summary refs log tree commit diff stats
path: root/tests/compile/tgenericshardcases.nim
diff options
context:
space:
mode:
Diffstat (limited to 'tests/compile/tgenericshardcases.nim')
-rw-r--r--tests/compile/tgenericshardcases.nim30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/compile/tgenericshardcases.nim b/tests/compile/tgenericshardcases.nim
new file mode 100644
index 000000000..90981c701
--- /dev/null
+++ b/tests/compile/tgenericshardcases.nim
@@ -0,0 +1,30 @@
+discard """
+  file: "tgenericshardcases.nim"
+  output: "int\nfloat\nint\nstring"
+"""
+
+import typetraits
+
+proc typeNameLen(x: typedesc): int {.compileTime.} =
+  result = x.name.len
+  
+macro selectType(a, b: typedesc): typedesc =
+  result = a
+
+type
+  Foo[T] = object
+    data1: array[high(T), int]
+    data2: array[1..typeNameLen(T), selectType(float, string)]
+
+  MyEnum = enum A, B, C,D
+
+var f1: Foo[MyEnum]
+var f2: Foo[int8]
+
+static:
+  assert high(f1.data1) == D
+  assert high(f1.data2) == 6 # length of MyEnum
+
+  assert high(f2.data1) == 127
+  assert high(f2.data2) == 4 # length of int8
+
s deploy stage to GitLab CI.' href='/ahoang/Nim/commit/.gitlab-ci.yml?h=devel&id=3e87ef35faa92333d6c78af1109d5da0cf0fc9c7'>3e87ef35f ^
cf40f3240 ^
e60868a78 ^
3e87ef35f ^




b790159bb ^
7e3ebc1bc ^





ef44c12a3 ^
6f1289b80 ^
7e3ebc1bc ^

3e87ef35f ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60