Improve vm support for ref types

This commit is contained in:
Oscar Nihlgård 2018-06-26 21:18:55 +02:00
commit 236bc06b5f
4 changed files with 79 additions and 23 deletions

View file

@ -9,4 +9,49 @@ static:
b[5] = 'c'
doAssert a[] == "Hellocworld"
doAssert b[] == "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