summary refs log tree commit diff stats
path: root/tests/array/tarraycons_ptr_generic.nim
diff options
context:
space:
mode:
authorMichael Voronin <survivor.mail@gmail.com>2018-05-03 17:12:01 +0300
committerGitHub <noreply@github.com>2018-05-03 17:12:01 +0300
commit5ea967d97a30f0084883d4efa81b05bea3e5d148 (patch)
tree05ea0e3624f6720c2f5af28b5a70c87c85feafc7 /tests/array/tarraycons_ptr_generic.nim
parent3949c9f977378ea3ab2b3c750f4dc2bc8d853022 (diff)
parent5564289b577c620cbd775f477b7fc8b6507adbfa (diff)
downloadNim-5ea967d97a30f0084883d4efa81b05bea3e5d148.tar.gz
Merge pull request #3 from nim-lang/devel
pull #3
Diffstat (limited to 'tests/array/tarraycons_ptr_generic.nim')
-rw-r--r--tests/array/tarraycons_ptr_generic.nim51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/array/tarraycons_ptr_generic.nim b/tests/array/tarraycons_ptr_generic.nim
new file mode 100644
index 000000000..eb89a196f
--- /dev/null
+++ b/tests/array/tarraycons_ptr_generic.nim
@@ -0,0 +1,51 @@
+discard """
+  output: '''apple
+banana
+Fruit
+2
+4
+3
+none
+skin
+paper
+'''
+"""
+type
+  Fruit = object of RootObj
+    name: string
+  Apple = object of Fruit
+  Banana = object of Fruit
+
+var
+  ir = Fruit(name: "Fruit")
+  ia = Apple(name: "apple")
+  ib = Banana(name: "banana")
+
+let x = [ia.addr, ib.addr, ir.addr]
+for c in x: echo c.name
+
+type
+  Vehicle[T] = object of RootObj
+    tire: T
+  Car[T] = object of Vehicle[T]
+  Bike[T] = object of Vehicle[T]
+
+var v = Vehicle[int](tire: 3)
+var c = Car[int](tire: 4)
+var b = Bike[int](tire: 2)
+
+let y = [b.addr, c.addr, v.addr]
+for c in y: echo c.tire
+
+type
+  Book[T] = ref object of RootObj
+    cover: T
+  Hard[T] = ref object of Book[T]
+  Soft[T] = ref object of Book[T]
+
+var bn = Book[string](cover: "none")
+var hs = Hard[string](cover: "skin")
+var bp = Soft[string](cover: "paper")
+
+let z = [bn, hs, bp]
+for c in z: echo c.cover