tmultim.nim 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. discard """
  2. output: '''
  3. collide: unit, thing
  4. collide: unit, thing
  5. collide: thing, unit
  6. collide: thing, thing
  7. collide: unit, thing |
  8. collide: unit, thing |
  9. collide: thing, unit |
  10. do nothing
  11. '''
  12. joinable: false
  13. disabled: true
  14. """
  15. # tmultim2
  16. type
  17. TThing = object {.inheritable.}
  18. TUnit = object of TThing
  19. x: int
  20. TParticle = object of TThing
  21. a, b: int
  22. method collide(a, b: TThing) {.base, inline.} =
  23. echo "collide: thing, thing"
  24. method collide(a: TThing, b: TUnit) {.inline.} =
  25. echo "collide: thing, unit"
  26. method collide(a: TUnit, b: TThing) {.inline.} =
  27. echo "collide: unit, thing"
  28. proc test(a, b: TThing) {.inline.} =
  29. collide(a, b)
  30. proc staticCollide(a, b: TThing) {.inline.} =
  31. procCall collide(a, b)
  32. var
  33. a: TThing
  34. b, c: TUnit
  35. collide(b, c) # ambiguous (unit, thing) or (thing, unit)? -> prefer unit, thing!
  36. test(b, c)
  37. collide(a, b)
  38. staticCollide(a, b)
  39. # tmultim6
  40. type
  41. Thing = object {.inheritable.}
  42. Unit[T] = object of Thing
  43. x: T
  44. Particle = object of Thing
  45. a, b: int
  46. method collide(a, b: Thing) {.base, inline.} =
  47. quit "to override!"
  48. method collide[T](a: Thing, b: Unit[T]) {.inline.} =
  49. echo "collide: thing, unit |"
  50. method collide[T](a: Unit[T], b: Thing) {.inline.} =
  51. echo "collide: unit, thing |"
  52. proc test(a, b: Thing) {.inline.} =
  53. collide(a, b)
  54. var
  55. aaa: Thing
  56. bbb, ccc: Unit[string]
  57. collide(bbb, Thing(ccc))
  58. test(bbb, ccc)
  59. collide(aaa, bbb)
  60. # tmethods1
  61. method somethin(obj: RootObj) {.base.} =
  62. echo "do nothing"
  63. type
  64. TNode* = object {.inheritable.}
  65. PNode* = ref TNode
  66. PNodeFoo* = ref object of TNode
  67. TSomethingElse = object
  68. PSomethingElse = ref TSomethingElse
  69. method foo(a: PNode, b: PSomethingElse) {.base.} = discard
  70. method foo(a: PNodeFoo, b: PSomethingElse) = discard
  71. var o: RootObj
  72. o.somethin()