tparameterizedparent2.nim 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. discard """
  2. output: '''(width: 11, color: 13)
  3. (width: 15, weight: 13, taste: 11, color: 14)
  4. (width: 17, color: 16)
  5. (width: 12.0, taste: "yummy", color: 13)
  6. (width: 0, tast_e: 0.0, kind: Smooth, skin: 1.5, color: 12)'''
  7. """
  8. # bug #5264
  9. type
  10. Texture = enum
  11. Smooth
  12. Coarse
  13. FruitBase = object of RootObj
  14. color: int
  15. Level2Fruit = object of FruitBase
  16. taste: int
  17. AppleBanana = object of Level2Fruit
  18. weight: int
  19. BaseFruit[T] = object of RootObj
  20. color: T
  21. Apple[T] = object of T
  22. width: int
  23. Peach[X, T, Y] = object of T
  24. width: X
  25. taste: Y
  26. Lemon[T] = object of T
  27. width: int
  28. tast_e: float64
  29. case kind: Texture
  30. of Smooth:
  31. skin: float64
  32. of Coarse:
  33. grain: int
  34. var x: Apple[FruitBase]
  35. x.color = 13
  36. x.width = 11
  37. echo x
  38. proc setColor(self: var FruitBase, c: int) =
  39. self.color = c
  40. proc setTaste[T](self: var Apple[T], c: int) =
  41. self.taste = c
  42. #proc setColor[T](self: var BaseFruit[T], c: int) =
  43. # self.color = c
  44. var y: Apple[AppleBanana]
  45. y.setColor(14)
  46. y.setTaste(11)
  47. y.weight = 13
  48. y.width = 15
  49. echo y
  50. var w: Apple[BaseFruit[int]]
  51. w.width = 17
  52. w.color = 16
  53. echo w
  54. var z: Peach[float64, BaseFruit[int], string]
  55. z.width = 12
  56. z.taste = "yummy"
  57. #z.setColor(13) #this trigger other bug
  58. z.color = 13
  59. echo z
  60. var k = Lemon[FruitBase](kind: Smooth, skin: 1.5)
  61. k.setColor(12)
  62. echo k