summary refs log tree commit diff stats
path: root/tests/objects/tobject.nim
blob: a185bebcb20403b490615823c56449a117da6486 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
type Obj = object
  foo: int

proc makeObj(x: int): Obj =
  result.foo = x

block: # object basic methods
  block: # it should convert an object to a string
    var obj = makeObj(1)
    # Should be "obj: (foo: 1)" or similar.
    doAssert($obj == "(foo: 1)")
  block: # it should test equality based on fields
    doAssert(makeObj(1) == makeObj(1))

# bug #10203

type
  TMyObj = TYourObj
  TYourObj = object of RootObj
    x, y: int

proc init: TYourObj =
  result.x = 0
  result.y = -1

proc f(x: var TYourObj) =
  discard

var m: TMyObj = init()
f(m)

var a: TYourObj = m
var b: TMyObj = a

# bug #10195
type
  InheritableFoo {.inheritable.} = ref object
  InheritableBar = ref object of InheritableFoo # ERROR.

block: # bug #14698
  const N = 3
  type Foo[T] = ref object
    x1: int
    when N == 2:
      x2: float
    when N == 3:
      x3: seq[int]
    else:
      x4: char
      x4b: array[9, char]

  let t = Foo[float](x1: 1)
  doAssert $(t[]) == "(x1: 1, x3: @[])"
  doAssert t.sizeof == int.sizeof
  type Foo1 = object
    x1: int
    x3: seq[int]
  doAssert t[].sizeof == Foo1.sizeof

# bug #147
type
  TValue* {.pure, final.} = object of RootObj
    a: int
  PValue = ref TValue
  PPValue = ptr PValue


var x: PValue
new x
var sp: PPValue = addr x

sp.a = 2
doAssert sp.a == 2