tobjecttyperel.nim 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. discard """
  2. output: '''(peel: 0, color: 15)
  3. (color: 15)
  4. 17
  5. (width: 0.0, taste: "", color: 13)
  6. (width: 0.0, taste: "", color: 15)
  7. cool'''
  8. """
  9. # bug #5241
  10. type
  11. BaseFruit[T] = object of RootObj
  12. color: T
  13. MidLevel[T] = object of BaseFruit[T]
  14. Mango = object of MidLevel[int]
  15. peel: int
  16. Peach[X, T, Y] = object of T
  17. width: X
  18. taste: Y
  19. proc setColor[T](self: var BaseFruit[T]) =
  20. self.color = 15
  21. proc setColor[T](self: var BaseFruit[T], c: int) =
  22. self.color = c
  23. var c: Mango
  24. setColor(c)
  25. echo c
  26. var d: MidLevel[int]
  27. setColor(d)
  28. echo d
  29. type
  30. FooBase[T] = ref object of RootRef
  31. v: T
  32. BarClient = ref object of FooBase[int]
  33. proc getColor[T](f: FooBase[T]): T = 17
  34. var b: BarClient
  35. echo getColor(b)
  36. var z: Peach[float64, BaseFruit[int], string]
  37. z.setColor(13)
  38. echo z
  39. z.setColor()
  40. echo z
  41. # bug #5411
  42. type
  43. Foo[T] = ref object of RootRef
  44. v: T
  45. Bar = ref object of Foo[int]
  46. method m(o: RootRef) {.base.} = assert(false, "Abstract method called")
  47. method m[T](o: Foo[T]) = echo "cool"
  48. var v: Bar
  49. v.new()
  50. v.m() # Abstract method not called anymore