summary refs log tree commit diff stats
path: root/tests/array
diff options
context:
space:
mode:
Diffstat (limited to 'tests/array')
-rw-r--r--tests/array/t7818.nim45
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/array/t7818.nim b/tests/array/t7818.nim
new file mode 100644
index 000000000..5d73efec5
--- /dev/null
+++ b/tests/array/t7818.nim
@@ -0,0 +1,45 @@
+discard """
+  msg: '''BracketExpr
+  Sym "array"
+  Infix
+    Ident ".."
+    IntLit 0
+    IntLit 2
+  BracketExpr
+    Sym "Vehicle"
+    Sym "int"
+---------
+BracketExpr
+  Sym "array"
+  Infix
+    Ident ".."
+    IntLit 0
+    IntLit 2
+  BracketExpr
+    Sym "Vehicle"
+    Sym "int"
+---------'''
+"""
+
+# bug #7818
+# this is not a macro bug, but array construction bug
+# I use macro to avoid object slicing
+# see #7712 and #7637
+import macros
+
+type
+  Vehicle[T] = object of RootObj
+    tire: T
+  Car[T] = object of Vehicle[T]
+  Bike[T] = object of Vehicle[T]
+
+macro peek(n: typed): untyped =
+  echo getTypeImpl(n).treeRepr
+  echo "---------"
+
+var v = Vehicle[int](tire: 3)
+var c = Car[int](tire: 4)
+var b = Bike[int](tire: 2)
+
+peek([c, b, v])
+peek([v, c, b])