Skip to content

Nullable(0, true) !== Nullable{Int}() false #16923

@nalimilan

Description

@nalimilan

Title says it all. It's possible to create two objects which are printed as Nullable{Int}() and are not supposed to differ in any way, and yet are actually different according to ===. This is because:

julia> dump(Nullable(0, true))
Nullable{Int64}
  isnull: Bool true
  value: Int64 0
julia> dump(Nullable{Int}())
Nullable{Int64}
  isnull: Bool true
  value: Int64 1

This is particularly annoying when writing tests, but it can also be disturbing in real uses.

For non-isbits types, a solution is to discard the value in the constructor when true, i.e.:

Nullable{T}(value::T, isnull::Bool=false) = ifelse(isnull, Nullable{T}(), Nullable(value))

But this doesn't work for isbits types, for which the field contains random values when left uninitialized. I guess there's a way to fill the value field with zeros à la reinterpret, but what's the best way to do it?

Cc: @johnmyleswhite

Metadata

Metadata

Assignees

No one assigned

    Labels

    missing 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