summary refs log tree commit diff stats
path: root/tests/objects/tinherentedvalues.nim
blob: c96a0fd6d507f9500d7304bf4555bc5bd1818322 (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
50
51
52
53
54
55
discard """
  output: '''tbObj of TC false
false
true
5
false'''
"""

# bug #1053
type
  TA = object of TObject
    a: int

  TB = object of TA
    b: int

  TC = object of TB
    c: int

proc test(p: TA) =
  #echo "p of TB ", p of TB
  if p of TB:
    var tbObj = TB(p)

    # tbObj is actually no longer compatible with TC:
    echo "tbObj of TC ", tbObj of TC

var v = TC()
v.a = 1
v.b = 2
v.c = 3
test(v)


# bug #924
type
  MyObject = object of TObject
    x: int

var
  asd: MyObject

proc isMyObject(obj: TObject) =
    echo obj of MyObject
    if obj of MyObject:
        let a = MyObject(obj)
        echo a.x

asd.x = 5

var asdCopy = TObject(asd)
echo asdCopy of MyObject

isMyObject(asd)
isMyObject(asdCopy)