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
Option type checking is more restrictive than it should be. It makes the usage of options verbose.
Description
When using Option, it is always mandatory to cast every object providing to it, even when types are compatible according to the type checker. It concerns inherited ref objects and proc() objects at least.
Here is an example :
import std/options
type
BaseObject = ref object of RootRef
ChildObject = ref object of BaseObject
Cb = proc()
var myObject: BaseObject
myObject = ChildObject() ## Works
var myOptionalObject: Option[BaseObject]
myOptionalObject = some ChildObject() ## Fail
myOptionalObject = some ChildObject().BaseObject ## Works
var myCallback: Cb
myCallback = proc() = discard ## Works
var myOptionalCallback: Option[Cb]
myOptionalCallback = some proc() = discard ## Fail
myOptionalCallback = some proc() {.closure, noSideEffect, gcsafe.} = discard ## Works
myOptionalCallback = some Cb(proc() = discard) ## Works
Expected behaviour
Assigning an Option value to an Option typed variable should have the same "compatability" as assigning a value to a standard typed variable.
Alternatives
No response
Examples
No response
Backwards Compatibility
No response
Links
No response
The text was updated successfully, but these errors were encountered:
Summary
Hello,
Option type checking is more restrictive than it should be. It makes the usage of options verbose.
Description
When using Option, it is always mandatory to cast every object providing to it, even when types are compatible according to the type checker. It concerns inherited ref objects and proc() objects at least.
Here is an example :
Expected behaviour
Assigning an Option value to an Option typed variable should have the same "compatability" as assigning a value to a standard typed variable.
Alternatives
No response
Examples
No response
Backwards Compatibility
No response
Links
No response
The text was updated successfully, but these errors were encountered: