Skip to content

Commit a7bb1f2

Browse files
committed
also fixes nim-lang#14420
1 parent e022e67 commit a7bb1f2

File tree

1 file changed

+53
-2
lines changed

1 file changed

+53
-2
lines changed

tests/misc/taddr.nim

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,52 @@ block:
124124
when false:
125125
proc byLent2[T](a: T): lent type(a[0]) = a[0]
126126

127+
proc test14420() = # bug #14420
128+
# s/proc/template/ would hit bug #16005
129+
block:
130+
type Foo = object
131+
x: float
132+
133+
proc fn(a: var Foo): var float =
134+
## WAS: discard <- turn this into a comment (or a `discard`) and error disappears
135+
# result = a.x # this works
136+
a.x # WAS: Error: limited VM support for 'addr'
137+
138+
proc fn2(a: var Foo): var float =
139+
result = a.x # this works
140+
a.x # WAS: Error: limited VM support for 'addr'
141+
142+
var a = Foo()
143+
discard fn(a)
144+
discard fn2(a)
145+
146+
block:
147+
proc byLent2[T](a: T): lent T =
148+
runnableExamples: discard
149+
a
150+
proc byLent3[T](a: T): lent T =
151+
runnableExamples: discard
152+
result = a
153+
var a = 10
154+
let x3 = byLent3(a) # works
155+
let x2 = byLent2(a) # WAS: Error: internal error: genAddr: nkStmtListExpr
156+
157+
block:
158+
type MyOption[T] = object
159+
case has: bool
160+
of true:
161+
value: T
162+
of false:
163+
discard
164+
func some[T](val: T): MyOption[T] =
165+
result = MyOption[T](has: true, value: val)
166+
func get[T](opt: MyOption[T]): lent T =
167+
doAssert opt.has
168+
# result = opt.value # this was ok
169+
opt.value # this had the bug
170+
let x = some(10)
171+
doAssert x.get() == 10
172+
127173
template test14339() = # bug #14339
128174
block:
129175
type
@@ -150,5 +196,10 @@ template test14339() = # bug #14339
150196
when not defined(js): # pending bug #16003
151197
doAssert a.val == 5
152198

153-
test14339()
154-
static: test14339()
199+
template main =
200+
# xxx wrap all other tests here like that so they're also tested in VM
201+
test14420()
202+
test14339()
203+
204+
static: main()
205+
main()

0 commit comments

Comments
 (0)