tcomplexobjconstr.nim 940 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. discard """
  2. output: '''true
  3. OK'''
  4. cmd: "nim c --gc:arc $file"
  5. """
  6. # bug #12826
  7. type
  8. MyObject1* = object of RootObj
  9. z*: string
  10. MyObject2* = object of RootObj
  11. x*: float
  12. name*: string
  13. subobj: MyObject1
  14. case flag*: bool
  15. of false:
  16. more: array[3, MyObject1]
  17. of true: y*: float
  18. var x = new(MyObject2)
  19. doAssert x of MyObject2
  20. doAssert x.subobj of MyObject1
  21. doAssert x.more[2] of MyObject1
  22. doAssert x.more[2] of RootObj
  23. var y: MyObject2
  24. doAssert y of MyObject2
  25. doAssert y.subobj of MyObject1
  26. doAssert y.more[2] of MyObject1
  27. doAssert y.more[2] of RootObj
  28. echo "true"
  29. # bug #12978
  30. type
  31. Vector2* = object of RootObj
  32. x*, y*: float
  33. type
  34. Vertex* = ref object
  35. point*: Vector2
  36. proc newVertex*(p: Vector2): Vertex =
  37. return Vertex(point: p)
  38. proc createVertex*(p: Vector2): Vertex =
  39. result = newVertex(p)
  40. proc p =
  41. var x = Vector2(x: 1, y: 2)
  42. let other = createVertex(x)
  43. echo "OK"
  44. p()