Open KarolBajkowski opened 3 weeks ago
Related #16754
@metagn Actually it might be exactly the same. I refined my example. It looks like this one also misbehaves:
import options
type Foo = ref object
name: string
abc: Option[Foo]
var foo1: Option[Foo] = none(Foo)
var foo2: Option[Foo] = foo1
if foo2.isSome:
echo "SHOULD NOT BE REACHABLE"
else:
echo "OK"
It prints "SHOULD NOT BE REACHABLE" as well.
Description
When the type contains a self-referenced optional field then during the variable assignment (value copy takes place I believe), the field 'isSome' has a wrong value. Below are the examples:
This works fine:
It will print: "OK"
however, when I add 'prev' field, this program misbehaves:
It will print "SHOULD NOT BE REACHABLE" which is an unexpected result.
Nim Version
Nim Compiler Version 2.0.8 [Windows: amd64] Compiled at 2024-07-03 Copyright (c) 2006-2023 by Andreas Rumpf
Current Output
No response
Expected Output
No response
Known Workarounds
Additional Information
No response