tinheritref.nim 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # bug #554, #179
  2. type T[E] =
  3. ref object
  4. elem: E
  5. var ob: T[int]
  6. ob = T[int](elem: 23)
  7. doAssert ob.elem == 23
  8. type
  9. TTreeIteratorA* = ref object {.inheritable.}
  10. TKeysIteratorA* = ref object of TTreeIteratorA #compiles
  11. TTreeIterator* [T,D] = ref object {.inheritable.}
  12. TKeysIterator* [T,D] = ref object of TTreeIterator[T,D] #this not
  13. var
  14. it: TKeysIterator[int, string] = nil
  15. #bug #5521
  16. type
  17. Texture = enum
  18. Smooth
  19. Coarse
  20. FruitBase = object of RootObj
  21. color: int
  22. case kind: Texture
  23. of Smooth:
  24. skin: float64
  25. of Coarse:
  26. grain: int
  27. Apple = object of FruitBase
  28. width: int
  29. taste: float64
  30. var x = Apple(kind: Smooth, skin: 1.5)
  31. var u = x.skin
  32. doAssert u == 1.5
  33. type
  34. BaseRef {.inheritable, pure.} = ref object
  35. baseRef: int
  36. SubRef = ref object of BaseRef
  37. BasePtr {.inheritable, pure.} = ptr object
  38. basePtr: int
  39. SubPtr = ptr object of BasePtr
  40. BaseObj {.inheritable, pure.} = object
  41. baseObj: int
  42. SubObj = object of BaseObj
  43. template baseObj[T](t: ptr T): untyped = T
  44. proc something123(): int =
  45. var r : SubRef
  46. r.new
  47. var p : SubPtr
  48. p = create(baseObj(p))
  49. var r2 : ref BaseObj
  50. r2.new
  51. var accu = 0
  52. # trigger code generation
  53. accu += r.baseRef
  54. accu += p.basePtr
  55. accu += r2.baseObj
  56. doAssert sizeof(r[]) == sizeof(int)
  57. doAssert sizeof(baseObj(p)) == sizeof(int)
  58. doAssert sizeof(r2[]) == sizeof(int)
  59. discard something123()