summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2014-11-03 16:31:31 +0100
committerAndreas Rumpf <rumpf_a@web.de>2014-11-03 16:31:31 +0100
commit0bfa26c2138201dce539efae594e7eef1a7f25a3 (patch)
tree5db9e3593ed406a1ac794971779743223bb0d1f9 /tests
parent33ce5c282e344affd63d0ba63e93ebb73752798c (diff)
parentce9a57fcfd21a1a3cb17087107c246f0492bec7f (diff)
downloadNim-0bfa26c2138201dce539efae594e7eef1a7f25a3.tar.gz
Merge pull request #1609 from rbehrends/fix-method-dispatch
Fix method recursion bug.
Diffstat (limited to 'tests')
-rw-r--r--tests/method/tmproto.nim25
-rw-r--r--tests/method/trecmeth.nim22
2 files changed, 47 insertions, 0 deletions
diff --git a/tests/method/tmproto.nim b/tests/method/tmproto.nim
new file mode 100644
index 000000000..5d75cff1a
--- /dev/null
+++ b/tests/method/tmproto.nim
@@ -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
diff --git a/tests/method/trecmeth.nim b/tests/method/trecmeth.nim
new file mode 100644
index 000000000..32f620f15
--- /dev/null
+++ b/tests/method/trecmeth.nim
@@ -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)
+