Fix generics inheritance issues
This commit is contained in:
parent
4b0ba5e3f1
commit
764668d099
2 changed files with 48 additions and 2 deletions
25
tests/generics/t88.nim
Normal file
25
tests/generics/t88.nim
Normal file
|
|
@ -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"
|
||||
Loading…
Add table
Add a link
Reference in a new issue