How to define `promote_rule` without including `Union{}` as an argument?

E.g., while using Polynomials.jl,

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> 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

 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
4 Likes