implemented generic multi methods

This commit is contained in:
Araq
2013-01-16 08:42:30 +01:00
parent c9690864d4
commit c43697b59a
9 changed files with 81 additions and 31 deletions

30
tests/run/tmultim6.nim Normal file
View File

@@ -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)