diff --git a/classes.nimble b/classes.nimble index fadc2a5..eefe8e9 100644 --- a/classes.nimble +++ b/classes.nimble @@ -1,5 +1,5 @@ # Package -version = "0.2.8" +version = "0.2.9" author = "jjv360" description = "Adds class support to Nim." license = "MIT" diff --git a/src/classes.nim b/src/classes.nim index 456ecc9..e450951 100644 --- a/src/classes.nim +++ b/src/classes.nim @@ -139,6 +139,7 @@ proc createClassStructure(head: NimNode, bodyNode: NimNode, result: NimNode, isS # Copy idents from the parent classInfo.varIdents.add(parentClassInfo.varIdents) classInfo.methodIdents.add(parentClassInfo.methodIdents) + classInfo.methodDefs.add(parentClassInfo.methodDefs) classInfo.mixinVars.add(parentClassInfo.mixinVars) classInfo.mixinMethods.add(parentClassInfo.mixinMethods) diff --git a/test.nim b/test.nim index 4a87656..1f40994 100644 --- a/test.nim +++ b/test.nim @@ -149,26 +149,6 @@ assert(ClassWith3Init.init(5, 5, 5, e=4.5, d=3.4).v1 == 15) -test "Constructor inheritance" - -class ClsInit1: - var v1 = 1 - method init() = this.v1 += 2 - -class ClsInit2 of ClsInit1: - method init() = - super.init() - this.v1 += 3 - -class ClsInit3 of ClsInit2: - method init() = - super.init() - this.v1 += 4 - -assert(ClsInit3.init().v1 == 10) - - - group "Destructors" test "Called on dealloc" warn "Not implemented yet" @@ -217,7 +197,7 @@ CommentB.init().d() -group "Superclass access" +group "Inheritance" test "Super constructor" class WithSuper3: var v1 = 5 @@ -247,6 +227,46 @@ assert(newWithSuper2().test2() == 5) +test "Constructor inheritance" + +class ClsInit1: + var v1 = 1 + method init() = this.v1 += 2 + +class ClsInit2 of ClsInit1: + method init() = + super.init() + this.v1 += 3 + +class ClsInit3 of ClsInit2: + method init() = + super.init() + this.v1 += 4 + +assert(ClsInit3.init().v1 == 10) + + + +test "Super call with skipped inheritance" + +class TestInheritanceA1: + var v1 = 1 + method increase() = this.v1 += 1 + +class TestInheritanceA2 of TestInheritanceA1 + +class TestInheritanceA3 of TestInheritanceA2: + method increase() = + super.increase() + this.v1 += 2 + +let inheritanceA = TestInheritanceA3.init() +inheritanceA.increase() +assert(inheritanceA.v1 == 4) + + + +