mirror of
https://github.com/nim-lang/Nim.git
synced 2026-05-01 03:24:41 +00:00
Merge pull request #1609 from rbehrends/fix-method-dispatch
Fix method recursion bug.
This commit is contained in:
25
tests/method/tmproto.nim
Normal file
25
tests/method/tmproto.nim
Normal file
@@ -0,0 +1,25 @@
|
||||
type
|
||||
Obj1 = ref object {.inheritable.}
|
||||
Obj2 = ref object of Obj1
|
||||
|
||||
method beta(x: Obj1): int
|
||||
|
||||
proc delta(x: Obj2): int =
|
||||
beta(x)
|
||||
|
||||
method beta(x: Obj2): int
|
||||
|
||||
proc alpha(x: Obj1): int =
|
||||
beta(x)
|
||||
|
||||
method beta(x: Obj1): int = 1
|
||||
method beta(x: Obj2): int = 2
|
||||
|
||||
proc gamma(x: Obj1): int =
|
||||
beta(x)
|
||||
|
||||
doAssert alpha(Obj1()) == 1
|
||||
doAssert gamma(Obj1()) == 1
|
||||
doAssert alpha(Obj2()) == 2
|
||||
doAssert gamma(Obj2()) == 2
|
||||
doAssert delta(Obj2()) == 2
|
||||
22
tests/method/trecmeth.nim
Normal file
22
tests/method/trecmeth.nim
Normal file
@@ -0,0 +1,22 @@
|
||||
# Note: We only compile this to verify that code generation
|
||||
# for recursive methods works, no code is being executed
|
||||
|
||||
type
|
||||
Obj = ref object of TObject
|
||||
|
||||
# Mutual recursion
|
||||
|
||||
method alpha(x: Obj)
|
||||
method beta(x: Obj)
|
||||
|
||||
method alpha(x: Obj) =
|
||||
beta(x)
|
||||
|
||||
method beta(x: Obj) =
|
||||
alpha(x)
|
||||
|
||||
# Simple recursion
|
||||
|
||||
method gamma(x: Obj) =
|
||||
gamma(x)
|
||||
|
||||
Reference in New Issue
Block a user