# Confusing ambiguous MethodError

While using SQLite.jl, I’ve run into this error (but I don’t think it is really a SQLite question.)

``````MethodError: promote_type(::Type{Union{}}, ::Type{String}) is ambiguous. Candidates:
promote_type(::Type{Union{}}, ::Type{T}) where T in Base at promotion.jl:280
promote_type(::Type{T}, ::Type{String}) where T<:WeakRefStrings.InlineString in WeakRefStrings at C:\Users\nritchie\.julia\packages\WeakRefStrings\a3jYm\src\inlinestrings.jl:44
Possible fix, define
promote_type(::Type{Union{}}, ::Type{String})
``````

If I understand correctly, `Union{}` is an empty union of types.
So the first promote candidate `promote_type(::Type{Union{}}, ::Type{T}) where T ` is saying that when selecting between type no type or type T, always promote to type T.
The second candidate says when selecting between an InlineString and a String, promote to String.
Now, given this, I don’t understand why the second candidate is being proposed for `promote_type(::Type{Union{}}, ::Type{String})`. As best I can tell, `::Type{Union{}}` does not match `::Type{<:InlineString}`.

What am I missing?

in the second method, the second argument is fixed to `Type{String}`, the `T <: Inline` applies to the first argument

Ok, I agree that the second argument is fixed to `::Type{String}` but how does `::Type{T} where T<: InlineString` match the first argument `::Type{Union{}}`?

If I do define a new
`promote_type(::Type{Union{}}, ::Type{String}) = String`
everything works but I don’t think I should need to.

The defining property of `Union{}` is that `Union{} <: T` is true for all types `T`.

That said, you should never overload `promote_type` directly, instead overload `promote_rule` for your custom type.

1 Like