summary refs log tree commit diff stats
path: root/tests/objects/tobject.nim
blob: 34856eaefb38b7dbf0eeebd299680fdfdacf6d58 (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
discard """
output: "[Suite] object basic methods"
"""

import unittest

type Obj = object
  foo: int

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

suite "object basic methods":
  test "it should convert an object to a string":
    var obj = makeObj(1)
    # Should be "obj: (foo: 1)" or similar.
    check($obj == "(foo: 1)")
  test "it should test equality based on fields":
    check(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.