# How to define \`promote\_rule\` without including \`Union{}\` as an argument?

**URL:** <https://discourse.julialang.org/t/how-to-define-promote-rule-without-including-union-as-an-argument/85609>\
**Category:** Internals & Design\
**Tags:** question, method-invalidation\
**Created:** [August 11, 2022, 8:54am UTC](https://discourse.julialang.org/t/how-to-define-promote-rule-without-including-union-as-an-argument/85609 "2022-08-11T08:54:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [August 11, 2022, 8:54am UTC](https://discourse.julialang.org/t/how-to-define-promote-rule-without-including-union-as-an-argument/85609/1 "2022-08-11T08:54:28Z")

</div>

E.g., while using `Polynomials.jl`,

```julia
julia> @which promote_rule(Polynomial{Int}, Union{})
promote_rule(::Type{<:AbstractPolynomial{T}}, ::Type{<:AbstractPolynomial{S}}) where {T, S}
     @ Polynomials ~/Dropbox/JuliaPackages/Polynomials.jl/src/common.jl:436

```

This issue arises because `Union{}` is a subtype of every type, even of concrete types

```julia
julia> Union{} <: Polynomial{Int,Vector{Int}}
true

```

but I’m certain that the package developer didn’t mean to include `Union{}` while defining the method.

This leads to invalidation, such as

```julia
 inserting promote_rule(::Type{PQ}, ::Type{S}) where {T, X, P<:AbstractPolynomial{T, X}, PQ<:AbstractRationalFunction{T, X, P}, S<:Number} @ Polynomials ~/Dropbox/JuliaPackages/Polynomials.jl/src/rational-functions/common.jl:104 invalidated:
   backedges: 1: superseding promote_rule(::Type{<:AbstractIrrational}, ::Type{T}) where T<:Real @ Base irrationals.jl:44 with MethodInstance for promote_rule(::Core.TypeofBottom, ::Type{UInt64}) (1 children)
              2: superseding promote_rule(::Type, ::Type) @ Base promotion.jl:319 with MethodInstance for promote_rule(::Type{T} where T<:Unsigned, ::Type{UInt64}) (5 children)
   36 mt_cache

```
