summary refs log tree commit diff stats
path: root/tests/destructor/tcaseobj_transitions.nim
blob: 61464101f0a2734a978f8a184d5882860e526573 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
discard """
  cmd: '''nim c --gc:arc $file'''
  output: '''no crash'''
"""

# bug #11205

type
  MyEnum = enum
    A, B, C
  MyCaseObject = object
    case kind: MyEnum
    of A: iseq: seq[int]
    of B: fseq: seq[float]
    of C: str: string


  MyCaseObjectB = object # carefully constructed to use the same enum,
                         # but a different object type!
    case kind: MyEnum
    of A, C: x: int
    of B: fseq: seq[float]


var x = MyCaseObject(kind: A)
x.iseq.add 1
#x.kind = B
#x.fseq.add -3.0

var y = MyCaseObjectB(kind: A)
y.x = 1
y.kind = C
echo "no crash"


#################
## bug #12821

type
  RefBaseObject* = ref object of RootObj
    case kind: bool
      of true: a: int
      of false: b: float

  MyRefObject = ref object of RefBaseObject
    x: float

let z = new(MyRefObject)
z.kind = false