summary refs log tree commit diff stats
path: root/tests/vm/tconstobj.nim
blob: 7dc20a0ba1fb8284f3656e765607a799f8e7f680 (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
discard """
  output: '''
(name: "hello")
(-1, 0)
(FirstName: "James", LastName: "Franco")
[1, 2, 3]
'''
"""

# bug #2774, bug #3195
type Foo = object
  name: string

const fooArray = [
  Foo(name: "hello")
]

echo fooArray[0]

type
    Position = object
        x, y: int

proc `$`(pos: Position): string =
    result = "(" & $pos.x & ", " & $pos.y & ")"

proc newPos(x, y: int): Position =
    result = Position(x: x, y: y)

const
     offset: array[1..4, Position] = [
         newPos(-1, 0),
         newPos(1, 0),
         newPos(0, -1),
         newPos(0, 1)
     ]

echo offset[1]

# bug #1547
import tables

type Person* = object
    FirstName*: string
    LastName*: string

let people = {
    "001": Person(FirstName: "James", LastName: "Franco")
}.toTable()

echo people["001"]

# Object downconversion should not copy

type
  SomeBaseObj  {.inheritable.} = object of RootObj
    txt : string
  InheritedFromBase = object of SomeBaseObj
    other : string

proc initBase(sbo: var SomeBaseObj) =
  sbo.txt = "Initialized string from base"

static:
  var ifb2: InheritedFromBase
  initBase(SomeBaseObj(ifb2))
  echo repr(ifb2)
  doAssert(ifb2.txt == "Initialized string from base")

static: # issue #11861
  var ifb2: InheritedFromBase
  initBase(ifb2)
  doAssert(ifb2.txt == "Initialized string from base")


static: # issue #15662
  proc a(T: typedesc) = echo T.type
  a((int, int))

# bug #16069
type
  E = enum
    val1, val2
  Obj = object
    case k: E
    of val1:
      x: array[3, int]
    of val2:
      y: uint32

const
  foo = [1, 2, 3]
  arr = Obj(k: val1, x: foo)

echo arr.x