diff options
author | LemonBoy <LemonBoy@users.noreply.github.com> | 2018-10-11 08:36:05 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-10-11 08:36:05 +0200 |
commit | 7775b7efd1f3a7eca434710d90368b98198019bd (patch) | |
tree | 3d0cf6e73d94c54caa353027444f4278a6a38261 /tests/ccgbugs | |
parent | 8ed3dac1dcffd5598be88520a76d7430324b6007 (diff) | |
download | Nim-7775b7efd1f3a7eca434710d90368b98198019bd.tar.gz |
Fix wrong heuristic in codegen (#9293)
A bare return may trigger the insertion of a genericReset. Fixes #9286
Diffstat (limited to 'tests/ccgbugs')
-rw-r--r-- | tests/ccgbugs/t9286.nim | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/ccgbugs/t9286.nim b/tests/ccgbugs/t9286.nim new file mode 100644 index 000000000..8a45a7bf6 --- /dev/null +++ b/tests/ccgbugs/t9286.nim @@ -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() |