Skip to content

There should be a zero(::Missing) method #28854

@yurivish

Description

@yurivish

zero(Missing) currently fails, as does one(Missing) and oneunit(Missing):

julia> zero(Missing)
ERROR: UndefVarError: T not defined

The error comes from this code in base/missing.jl:

for f in (:(Base.zero), :(Base.one), :(Base.oneunit))
    @eval function $(f)(::Type{Union{T, Missing}}) where T
        T === Any && throw(MethodError($f, (Any,)))  # To prevent StackOverflowError
        $f(T)
    end
end

Perhaps zero(::Missing) and one(::Missing) should be missing, since missing + missing == missing and the same for * and those two methods give you the additive and multiplicative identities.

@ararslan suggests adding @eval $(f)(::Type{Missing}) = missing to the loop.

Metadata

Metadata

Assignees

No one assigned

    Labels

    mathsMathematical functionsmissing dataBase.missing and related functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions