function fun(x::Union{AbstractArray{T}, AbstractArray{Union{T, Missing}}};
α::T = T(3.0) ) where {T<:AbstractFloat}
println(typeof(x))
end
julia> fun([1.0, 2.0])
Vector{Float64}
julia> fun([1.0, missing, 2.0])
Vector{Union{Missing, Float64}}
on above, everything is fine with only one input belongs to either AbstractArray{T}
or AbstractArray{Union{T, Missing}}
.
Now, for a function with two those inputs:
function gun(x::Union{AbstractArray{T}, AbstractArray{Union{T, Missing}}},
y::Union{AbstractArray{T}, AbstractArray{Union{T, Missing}}};
α::T = T(3.0) ) where {T<:AbstractFloat}
println(typeof(x), " ", typeof(y))
end
julia> gun([1.0, 2.0], [3.0, 4.0])
Vector{Float64} Vector{Float64}
julia> gun([1.0, 2.0], [3.0, 4.0, missing])
Vector{Float64} Vector{Union{Missing, Float64}}
julia> gun([1.0, missing, 2.0], [3.0, 4.0, missing])
ERROR: MethodError: no method matching Union{Missing, Float64}(::Float64)
Stacktrace:
[1] gun(x::Vector{Union{Missing, Float64}}, y::Vector{Union{Missing, Float64}})
@ Main ./REPL[38]:3
[2] top-level scope
@ REPL[43]:1
error seems coming from mistaking Union{Missing, Float64}
as T
, which should be Float64
, in the default keyword argument assignment.
noted that if I supply the keyboard argument such that the default value assignment is not called, no error:
julia> gun([1.0, missing, 2.0], [3.0, 4.0, missing]; α = 1.0)
Vector{Union{Missing, Float64}} Vector{Union{Missing, Float64}}
it seems to be a bug in extracting the T
(when Union
is involved?). using v1.6.1. thanks.