summary refs log tree commit diff stats
path: root/tests/method/tmultim6.nim
blob: 5f45f572a39203fe89c1f7bfaa8585afb1fbe95a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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)