summary refs log tree commit diff stats
path: root/tests/run/tmultim6.nim
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2013-01-16 08:42:30 +0100
committerAraq <rumpf_a@web.de>2013-01-16 08:42:30 +0100
commitc43697b59a08459fdfe41129b9ed0f96cf0150fa (patch)
tree8c1a9c2e3f4f915791922e45fcbaede72aa9c0b3 /tests/run/tmultim6.nim
parentc9690864d4cf9945cb5eb9497f7621e56f9bebd0 (diff)
downloadNim-c43697b59a08459fdfe41129b9ed0f96cf0150fa.tar.gz
implemented generic multi methods
Diffstat (limited to 'tests/run/tmultim6.nim')
-rw-r--r--tests/run/tmultim6.nim30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/run/tmultim6.nim b/tests/run/tmultim6.nim
new file mode 100644
index 000000000..a55b69e37
--- /dev/null
+++ b/tests/run/tmultim6.nim
@@ -0,0 +1,30 @@
+discard """
+  output: "collide: unit, thing | collide: unit, thing | collide: thing, unit"
+"""
+# Test multi methods
+
+type
+  TThing = object {.inheritable.}
+  TUnit[T] = object of TThing
+    x: T
+  TParticle = object of TThing
+    a, b: int
+    
+method collide(a, b: TThing) {.inline.} =
+  quit "to override!"
+  
+method collide[T](a: TThing, b: TUnit[T]) {.inline.} =
+  write stdout, "collide: thing, unit | "
+
+method collide[T](a: TUnit[T], b: TThing) {.inline.} =
+  write stdout, "collide: unit, thing | "
+
+proc test(a, b: TThing) {.inline.} =
+  collide(a, b)
+
+var
+  a: TThing
+  b, c: TUnit[string]
+collide(b, TThing(c))
+test(b, c)
+collide(a, b)