Adding Type to (working) Union{...} bricks it

Julia treats the possible absence of a value (nothing) as a special case. Calling convert on the abstract type Union{Nothing, T} basically strips the Nothing. From the source:

For MyStruct1 we have T = Dict{Union{UInt8, String}, Number} for which a conversion is possible. In the case of MyStruct2, T = Union{Dict{Union{UInt8, String}, Number}, String} for which no conversion exists. In particular because it is an abstract type.

So in short: Union{Nothing, ConcreteType} is handled conveniently.

1 Like