mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
31 lines
649 B
Nim
31 lines
649 B
Nim
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) {.base, 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)
|