File: tmultim6.nim

package info (click to toggle)
nim 0.19.4-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 462,356 kB
  • sloc: sh: 11,089; ansic: 4,699; makefile: 706; python: 309; sql: 297; asm: 141; xml: 13
file content (30 lines) | stat: -rw-r--r-- 635 bytes parent folder | download | duplicates (3)
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
  Thing = object {.inheritable.}
  Unit[T] = object of Thing
    x: T
  Particle = object of Thing
    a, b: int

method collide(a, b: Thing) {.base, inline.} =
  quit "to override!"

method collide[T](a: Thing, b: Unit[T]) {.inline.} =
  write stdout, "collide: thing, unit | "

method collide[T](a: Unit[T], b: Thing) {.inline.} =
  write stdout, "collide: unit, thing | "

proc test(a, b: Thing) {.inline.} =
  collide(a, b)

var
  a: Thing
  b, c: Unit[string]
collide(b, Thing(c))
test(b, c)
collide(a, b)