# Confusing ambiguous MethodError

**URL:** <https://discourse.julialang.org/t/confusing-ambiguous-methoderror/73380>\
**Category:** General Usage\
**Created:** [December 20, 2021, 4:30pm UTC](https://discourse.julialang.org/t/confusing-ambiguous-methoderror/73380 "2021-12-20T16:30:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![NicholasWMRitchie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nicholaswmritchie/32/22449_2.png) [@NicholasWMRitchie](https://discourse.julialang.org/u/NicholasWMRitchie)\
**Post date:** [December 20, 2021, 4:30pm UTC](https://discourse.julialang.org/t/confusing-ambiguous-methoderror/73380/1 "2021-12-20T16:30:23Z")

</div>

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

```julia
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?

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [December 20, 2021, 4:38pm UTC](https://discourse.julialang.org/t/confusing-ambiguous-methoderror/73380/2 "2021-12-20T16:38:28Z")

</div>

> [@NicholasWMRitchie](#):
>
> not match `::Type{<:InlineString}` .

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

---

<div class="post-metadata">

**Author:** ![NicholasWMRitchie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nicholaswmritchie/32/22449_2.png) [@NicholasWMRitchie](https://discourse.julialang.org/u/NicholasWMRitchie)\
**Post date:** [December 20, 2021, 4:46pm UTC](https://discourse.julialang.org/t/confusing-ambiguous-methoderror/73380/3 "2021-12-20T16:46:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)\
**Post date:** [December 20, 2021, 5:00pm UTC](https://discourse.julialang.org/t/confusing-ambiguous-methoderror/73380/4 "2021-12-20T17:00:10Z")

</div>

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.
