Fix wrong heuristic in codegen (#9293)
A bare return may trigger the insertion of a genericReset. Fixes #9286
This commit is contained in:
parent
8ed3dac1dc
commit
7775b7efd1
2 changed files with 29 additions and 1 deletions
22
tests/ccgbugs/t9286.nim
Normal file
22
tests/ccgbugs/t9286.nim
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
discard """
|
||||
action: run
|
||||
"""
|
||||
|
||||
import options
|
||||
type Foo = ref object
|
||||
i: int
|
||||
|
||||
proc next(foo: Foo): Option[Foo] =
|
||||
try: assert(foo.i == 0)
|
||||
except: return # 2º: none
|
||||
return some(foo) # 1º: some
|
||||
|
||||
proc test =
|
||||
let foo = Foo()
|
||||
var opt = next(foo) # 1º Some
|
||||
while isSome(opt) and foo.i < 10:
|
||||
inc(foo.i)
|
||||
opt = next(foo) # 2º None
|
||||
assert foo.i == 1, $foo.i
|
||||
|
||||
test()
|
||||
Loading…
Add table
Add a link
Reference in a new issue