Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Argument order dependency in dispatching on Type{Union{T,S}} and Type{T} #30751

Open
tkf opened this issue Jan 18, 2019 · 0 comments
Open

Argument order dependency in dispatching on Type{Union{T,S}} and Type{T} #30751

tkf opened this issue Jan 18, 2019 · 0 comments
Labels
types and dispatch Types, subtyping and method dispatch

Comments

@tkf
Copy link
Member

tkf commented Jan 18, 2019

Originally discussed in: https://discourse.julialang.org/t/19732/5

Following "poor man's typesubtract" does not work:

julia> f(::Type{Union{T,S}}, ::Type{T}) where {S, T} = S
f (generic function with 1 method)

julia> f(Union{Missing, Float64, Int}, Missing)
ERROR: MethodError: no method matching f(::Type{Union{Missing, Float64, Int64}}, ::Type{Missing})
Closest candidates are:
  f(::Type{Union{T, S}}, ::Type{T}) where {S, T} at REPL[2]:1
Stacktrace:
 [1] top-level scope at REPL[3]:1

However, it works when the order of arguments is reversed:

julia> g(::Type{T}, ::Type{Union{T,S}}) where {S, T} = S
g (generic function with 1 method)

julia> g(Missing, Union{Missing, Float64, Int})
Union{Float64, Int64}

I checked it with 1.2.0-DEV.146. I also noticed that both of them work with 0.6.4. This could be a duplicate of #26135 and #24333. But since none of them mention the order of arguments, I post it just in case.

@JeffBezanson JeffBezanson added the types and dispatch Types, subtyping and method dispatch label Jan 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
types and dispatch Types, subtyping and method dispatch
Projects
None yet
Development

No branches or pull requests

2 participants