tcaseobj_transitions.nim 829 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. discard """
  2. cmd: '''nim c --gc:arc $file'''
  3. output: '''no crash'''
  4. """
  5. # bug #11205
  6. type
  7. MyEnum = enum
  8. A, B, C
  9. MyCaseObject = object
  10. case kind: MyEnum
  11. of A: iseq: seq[int]
  12. of B: fseq: seq[float]
  13. of C: str: string
  14. MyCaseObjectB = object # carefully constructed to use the same enum,
  15. # but a different object type!
  16. case kind: MyEnum
  17. of A, C: x: int
  18. of B: fseq: seq[float]
  19. var x = MyCaseObject(kind: A)
  20. x.iseq.add 1
  21. #x.kind = B
  22. #x.fseq.add -3.0
  23. var y = MyCaseObjectB(kind: A)
  24. y.x = 1
  25. y.kind = C
  26. echo "no crash"
  27. #################
  28. ## bug #12821
  29. type
  30. RefBaseObject* = ref object of RootObj
  31. case kind: bool
  32. of true: a: int
  33. of false: b: float
  34. MyRefObject = ref object of RefBaseObject
  35. x: float
  36. let z = new(MyRefObject)
  37. z.kind = false