* fix #14339: fixes limited VM support for addr * strengthen test * reference bug #16003 * also fixes #13511 * also fixes #14420
This commit is contained in:
parent
7848da7abe
commit
3e7077ac7d
4 changed files with 160 additions and 44 deletions
|
|
@ -123,3 +123,83 @@ block:
|
|||
block: # pending bug #15959
|
||||
when false:
|
||||
proc byLent2[T](a: T): lent type(a[0]) = a[0]
|
||||
|
||||
proc test14420() = # bug #14420
|
||||
# s/proc/template/ would hit bug #16005
|
||||
block:
|
||||
type Foo = object
|
||||
x: float
|
||||
|
||||
proc fn(a: var Foo): var float =
|
||||
## WAS: discard <- turn this into a comment (or a `discard`) and error disappears
|
||||
# result = a.x # this works
|
||||
a.x # WAS: Error: limited VM support for 'addr'
|
||||
|
||||
proc fn2(a: var Foo): var float =
|
||||
result = a.x # this works
|
||||
a.x # WAS: Error: limited VM support for 'addr'
|
||||
|
||||
var a = Foo()
|
||||
discard fn(a)
|
||||
discard fn2(a)
|
||||
|
||||
block:
|
||||
proc byLent2[T](a: T): lent T =
|
||||
runnableExamples: discard
|
||||
a
|
||||
proc byLent3[T](a: T): lent T =
|
||||
runnableExamples: discard
|
||||
result = a
|
||||
var a = 10
|
||||
let x3 = byLent3(a) # works
|
||||
let x2 = byLent2(a) # WAS: Error: internal error: genAddr: nkStmtListExpr
|
||||
|
||||
block:
|
||||
type MyOption[T] = object
|
||||
case has: bool
|
||||
of true:
|
||||
value: T
|
||||
of false:
|
||||
discard
|
||||
func some[T](val: T): MyOption[T] =
|
||||
result = MyOption[T](has: true, value: val)
|
||||
func get[T](opt: MyOption[T]): lent T =
|
||||
doAssert opt.has
|
||||
# result = opt.value # this was ok
|
||||
opt.value # this had the bug
|
||||
let x = some(10)
|
||||
doAssert x.get() == 10
|
||||
|
||||
template test14339() = # bug #14339
|
||||
block:
|
||||
type
|
||||
Node = ref object
|
||||
val: int
|
||||
proc bar(c: Node): var int =
|
||||
var n = c # was: Error: limited VM support for 'addr'
|
||||
c.val
|
||||
var a = Node()
|
||||
discard a.bar()
|
||||
block:
|
||||
type
|
||||
Node = ref object
|
||||
val: int
|
||||
proc bar(c: Node): var int =
|
||||
var n = c
|
||||
doAssert n.val == n[].val
|
||||
n.val
|
||||
var a = Node(val: 3)
|
||||
a.bar() = 5
|
||||
when nimvm:
|
||||
doAssert a.val == 5
|
||||
else:
|
||||
when not defined(js): # pending bug #16003
|
||||
doAssert a.val == 5
|
||||
|
||||
template main =
|
||||
# xxx wrap all other tests here like that so they're also tested in VM
|
||||
test14420()
|
||||
test14339()
|
||||
|
||||
static: main()
|
||||
main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue