Skip to content

Commit

Permalink
also fixes nim-lang#14420
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Nov 25, 2020
1 parent e022e67 commit a7bb1f2
Showing 1 changed file with 53 additions and 2 deletions.
55 changes: 53 additions & 2 deletions tests/misc/taddr.nim
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,52 @@ block:
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
Expand All @@ -150,5 +196,10 @@ template test14339() = # bug #14339
when not defined(js): # pending bug #16003
doAssert a.val == 5

test14339()
static: test14339()
template main =
# xxx wrap all other tests here like that so they're also tested in VM
test14420()
test14339()

static: main()
main()

0 comments on commit a7bb1f2

Please sign in to comment.