Skip to content

Commit

Permalink
Fixed bug with inheritance when inbetween class does not implement a …
Browse files Browse the repository at this point in the history
…method
  • Loading branch information
jjv360 committed Dec 27, 2021
1 parent 05af942 commit bf1fad9
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 22 deletions.
2 changes: 1 addition & 1 deletion classes.nimble
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Package
version = "0.2.8"
version = "0.2.9"
author = "jjv360"
description = "Adds class support to Nim."
license = "MIT"
Expand Down
1 change: 1 addition & 0 deletions src/classes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
62 changes: 41 additions & 21 deletions test.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -217,7 +197,7 @@ CommentB.init().d()



group "Superclass access"
group "Inheritance"
test "Super constructor"
class WithSuper3:
var v1 = 5
Expand Down Expand Up @@ -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)







Expand Down

0 comments on commit bf1fad9

Please sign in to comment.