Skip to content

Union with None / NoneType type does not behave as expected #739

@yfinkelstein

Description

@yfinkelstein

I have a function with this signature:

def get_value(self)-> Union[NoneType, bool, i32, i64, float, str]:

Sometime this function returns None

When this happens, printing a returned value results in this :

ValueError: optional unpack failed: expected Union[Int[32] | Int[64] | NoneType | bool | float | str], got None

Raised from: std.internal.types.optional.unwrap.0:0
/Users/yfinkelstein/.codon/lib/codon/stdlib/internal/types/optional.codon:99:5

Is there a better way to model a return type that has a nuber of type alternatives or None ?

Also, another strange behavior:
if the function does not return anything ( a branch that does not have a return statement and just exits), the returned value has the type of the first template type in the Union after sorting by type name

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions