tobjects_issues.nim 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. discard """
  2. output: '''
  3. tbObj of TC true
  4. true
  5. 5
  6. true
  7. is Nil false
  8. '''
  9. """
  10. block t1053:
  11. type
  12. TA = object of RootObj
  13. a: int
  14. TB = object of TA
  15. b: int
  16. TC = object of TB
  17. c: int
  18. proc test(p: TA) =
  19. if p of TB:
  20. echo "tbObj of TC ", p of TC
  21. var v = TC()
  22. v.a = 1
  23. v.b = 2
  24. v.c = 3
  25. test(v)
  26. block t924:
  27. type
  28. MyObject = object of RootObj
  29. x: int
  30. var asd: MyObject
  31. proc isMyObject(obj: RootObj) =
  32. echo obj of MyObject
  33. if obj of MyObject:
  34. let a = MyObject(obj)
  35. echo a.x
  36. asd.x = 5
  37. isMyObject(asd)
  38. block t4673:
  39. type
  40. BaseObj[T] = ref object of RootObj
  41. SomeObj = ref object of BaseObj[int]
  42. proc doSomething[T](o: BaseObj[T]) =
  43. echo "true"
  44. var o = new(SomeObj)
  45. o.doSomething() # Error: cannot instantiate: 'T'
  46. block t1658:
  47. type
  48. Loop = ref object
  49. onBeforeSelect: proc (L: Loop)
  50. var L: Loop
  51. new L
  52. L.onBeforeSelect = proc (bar: Loop) =
  53. echo "is Nil ", bar.isNil
  54. L.onBeforeSelect(L)
  55. block t2508:
  56. type
  57. GenericNodeObj[T] = ref object
  58. obj: T
  59. Node = ref object
  60. children: seq[Node]
  61. parent: Node
  62. nodeObj: GenericNodeObj[int]
  63. proc newNode(nodeObj: GenericNodeObj): Node =
  64. result = Node(nodeObj: nodeObj)
  65. newSeq(result.children, 10)
  66. var genericObj = GenericNodeObj[int]()
  67. var myNode = newNode(genericObj)
  68. block t2540:
  69. type
  70. BaseSceneNode[T] = ref object of RootObj
  71. children: seq[BaseSceneNode[T]]
  72. parent: BaseSceneNode[T]
  73. SceneNode[T] = ref object of BaseSceneNode[T]
  74. SomeObj = ref object
  75. proc newSceneNode[T](): SceneNode[T] =
  76. new result
  77. result.children = @[]
  78. var aNode = newSceneNode[SomeObj]()
  79. block t3038:
  80. type
  81. Data[T] = ref object of RootObj
  82. data: T
  83. Type = ref object of RootObj
  84. SubType[T] = ref object of Type
  85. data: Data[T]
  86. SubSubType = ref object of SubType[int]
  87. SubSubSubType = ref object of SubSubType