tobjecttyperel.nim 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. discard """
  2. matrix: "-d:nimInternalNonVtablesTesting"
  3. output: '''(peel: 0, color: 15)
  4. (color: 15)
  5. 17
  6. (width: 0.0, taste: "", color: 13)
  7. (width: 0.0, taste: "", color: 15)
  8. cool
  9. test'''
  10. """
  11. # bug #5241
  12. type
  13. BaseFruit[T] = object of RootObj
  14. color: T
  15. MidLevel[T] = object of BaseFruit[T]
  16. Mango = object of MidLevel[int]
  17. peel: int
  18. Peach[X, T, Y] = object of T
  19. width: X
  20. taste: Y
  21. proc setColor[T](self: var BaseFruit[T]) =
  22. self.color = 15
  23. proc setColor[T](self: var BaseFruit[T], c: int) =
  24. self.color = c
  25. var c: Mango
  26. setColor(c)
  27. echo c
  28. var d: MidLevel[int]
  29. setColor(d)
  30. echo d
  31. type
  32. FooBase[T] = ref object of RootRef
  33. v: T
  34. BarClient = ref object of FooBase[int]
  35. proc getColor[T](f: FooBase[T]): T = 17
  36. var b: BarClient
  37. echo getColor(b)
  38. var z: Peach[float64, BaseFruit[int], string]
  39. z.setColor(13)
  40. echo z
  41. z.setColor()
  42. echo z
  43. # bug #5411
  44. type
  45. Foo[T] = ref object of RootRef
  46. v: T
  47. Bar = ref object of Foo[int]
  48. method m(o: RootRef) {.base.} = assert(false, "Abstract method called")
  49. method m[T](o: Foo[T]) = echo "cool"
  50. var v: Bar
  51. v.new()
  52. v.m() # Abstract method not called anymore
  53. # bug #88
  54. type
  55. TGen[T] = object of RootObj
  56. field: T
  57. TDerived[T] = object of TGen[T]
  58. nextField: T
  59. proc doSomething[T](x: ref TGen[T]) =
  60. type
  61. Ty = ref TDerived[T]
  62. echo Ty(x).nextField
  63. var
  64. x: ref TDerived[string]
  65. new(x)
  66. x.nextField = "test"
  67. doSomething(x)