You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
import options
type Foo = ref object
name: string
var foo1: Option[Foo] = none(Foo)
var foo2: Option[Foo] = foo1
if foo2.isSome:
echo "SHOULD NOT BE REACHABLE"
else:
echo "OK"
It will print: "OK"
however, when I add 'prev' field, this program misbehaves:
import options
type Foo = ref object
name: string
prev: Option[Foo] # <-- this has been added
var foo1: Option[Foo] = none(Foo)
var foo2: Option[Foo] = foo1
if foo2.isSome:
echo "SHOULD NOT BE REACHABLE"
else:
echo "OK"
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
import options
type
Foo = ref FooObj
FooObj = 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"
Additional Information
No response
The text was updated successfully, but these errors were encountered:
@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.
KarolBajkowski
changed the title
When 'prev' field is defined inside a type then the option type behaves in a wrong way during an assignment
When self referenced field is defined inside a ref type then the option type behaves in a wrong way during an assignment
Sep 18, 2024
KarolBajkowski
changed the title
When self referenced field is defined inside a ref type then the option type behaves in a wrong way during an assignment
When self referenced optional field is defined inside a ref type then the option type behaves in a wrong way during an assignment
Sep 18, 2024
KarolBajkowski
changed the title
When self referenced optional field is defined inside a ref type then the option type behaves in a wrong way during an assignment
When self-referenced optional field is defined inside a ref type then the option type behaves in a wrong way during an assignment
Sep 18, 2024
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
The text was updated successfully, but these errors were encountered: