Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std/options is very picky on the types #23569

Open
Alogani opened this issue May 4, 2024 · 0 comments
Open

std/options is very picky on the types #23569

Alogani opened this issue May 4, 2024 · 0 comments

Comments

@Alogani
Copy link

Alogani commented May 4, 2024

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 :

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant