Automatic conversion Int64 ->Float64 for Unions

Currently integers to floats “automatic” conversion is successful only if the type is not a Union but it fails otherwise:

a = Float64[1.0,2.0]
a = Float64[1,2]                      # ok

a = Union{Float64,String}[1.0,"aaa"]
a = Union{Float64,String}[1,"aaa"]    # MethodError

From a user-centric point of view, is there a way that integer to float could be handled automatically even in cases of Unions without ambiguity or performance losses ?

1 Like

I don’t think this is possible automatically. If the union was Union{Int32, Float64} what does Int convert to?