summary refs log tree commit diff stats
path: root/tests/generics
diff options
context:
space:
mode:
authorAnatoly Galiulin <galiulin.anatoly@gmail.com>2016-06-23 18:37:14 +0600
committerAnatoly Galiulin <galiulin.anatoly@gmail.com>2016-06-23 18:37:14 +0600
commit764668d099a67ef6b877d07e4857c92d5774fe98 (patch)
treea4a3c74cc62784e6bb4f18158b6690282ce7c3bb /tests/generics
parent4b0ba5e3f1b78b3c45a3f1576ed3d60f9a8b6d80 (diff)
downloadNim-764668d099a67ef6b877d07e4857c92d5774fe98.tar.gz
Fix generics inheritance issues
Diffstat (limited to 'tests/generics')
-rw-r--r--tests/generics/t88.nim25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/generics/t88.nim b/tests/generics/t88.nim
new file mode 100644
index 000000000..93d93f063
--- /dev/null
+++ b/tests/generics/t88.nim
@@ -0,0 +1,25 @@
+# Issue 88
+
+type
+  BaseClass[V] = object of RootObj
+    b: V
+
+proc new[V](t: typedesc[BaseClass], v: V): BaseClass[V] =
+  BaseClass[V](b: v)
+
+proc baseMethod[V](v: BaseClass[V]): V = v.b
+proc overridedMethod[V](v: BaseClass[V]): V = v.baseMethod
+
+type
+  ChildClass[V] = object of BaseClass[V]
+    c: V
+
+proc new[V](t: typedesc[ChildClass], v1, v2: V): ChildClass[V] =
+  ChildClass[V](b: v1, c: v2)
+
+proc overridedMethod[V](v: ChildClass[V]): V = v.c
+
+let c = ChildClass[string].new("Base", "Child")
+
+assert c.baseMethod == "Base"
+assert c.overridedMethod == "Child"