summary refs log tree commit diff stats
path: root/tests/js/trefbyvar.nim
blob: 314a02543a61b20175b1a31a731185630ee67ba5 (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
discard """
  output: '''0
5
0
5
@[1, 2]
~'''
"""

# bug #2476

type A = ref object
    m: int

proc f(a: var A) =
    var b: A
    b.new()
    b.m = 5
    a = b

var t: A
t.new()

echo t.m
t.f()
echo t.m

proc main =
  # now test the same for locals
  var t: A
  t.new()

  echo t.m
  t.f()
  echo t.m

main()

# bug #5974
type
  View* = object
    data: ref seq[int]

let a = View(data: new(seq[int]))
a.data[] = @[1, 2]

echo a.data[]

# bug #5379
var input = newSeq[ref string]()
input.add(nil)
input.add(new string)
input[1][] = "~"
echo input[1][]