summary refs log tree commit diff stats
path: root/tests/vm/tref.nim
blob: e70305225637664be65cac9e1be30b5050def254 (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
static:
  var
    a: ref string
    b: ref string
  new a

  a[] = "Hello world"
  b = a

  b[5] = 'c'
  doAssert a[] == "Hellocworld"
  doAssert b[] == "Hellocworld"

  proc notGlobal() =
    var
      a: ref string
      b: ref string
    new a

    a[] = "Hello world"
    b = a

    b[5] = 'c'
    doAssert a[] == "Hellocworld"
    doAssert b[] == "Hellocworld"
  notGlobal()

static: # bug 6081
  block:
    type Obj = object
      field: ref int
    var i: ref int
    new(i)
    var r = Obj(field: i)
    var rr = r
    r.field = nil
    doAssert rr.field != nil

  proc foo() = # Proc to avoid special global logic
    var s: seq[ref int]
    var i: ref int
    new(i)
    s.add(i)
    var head = s[0]
    s[0] = nil
    doAssert head != nil

  foo()

static:

  block: # global alias
    var s: ref int
    new(s)
    var ss = s
    s[] = 1
    doAssert ss[] == 1

static: # bug #8402
  type R = ref object
  var empty: R
  let otherEmpty = empty

block:
  # fix https://github.com/timotheecour/Nim/issues/88
  template fun() =
    var s = @[10,11,12]
    var a = s[0].addr
    a[] += 100 # was giving SIGSEGV
    doAssert a[] == 110
  static: fun()