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

f(::Type{Union{Missing, T}}) where {T} = T throws MethodError when T isa UnionAll #26135

Open
iamed2 opened this issue Feb 20, 2018 · 10 comments
Labels
types and dispatch Types, subtyping and method dispatch

Comments

@iamed2
Copy link
Contributor

iamed2 commented Feb 20, 2018

This, as far as I can tell, needs to not throw and actually run to implement Missings.T (which is the function f above). See JuliaData/Missings.jl#80 . This issue presented differently on 0.6.

@StefanKarpinski
Copy link
Member

StefanKarpinski commented Feb 20, 2018

Example failure:

julia> f(Union{Missing, Tuple{Integer}})
ERROR: UndefVarError: T not defined
Stacktrace:
 [1] f(::Type{Union{Missing, Tuple{X} where X<:Integer}}) at ./REPL[17]:1
 [2] top-level scope

@vtjnash
Copy link
Member

vtjnash commented Feb 20, 2018

I'm tempted to say we should make this always an UndefVarError

@iamed2
Copy link
Contributor Author

iamed2 commented Feb 21, 2018

I'm not particularly attached to this specific behaviour but we do need a way to get Array{Int, N} where N from Union{Missing, Array{Int, N} where N}.

I do think UndefVarError would not be very user-friendly, and a more specific error message would be helpful.

@martinholters
Copy link
Member

I'm getting

julia> f(Union{Missing, Tuple{Integer}})
Tuple{Integer}

julia> f(Union{Missing,Array{Int,1}})
Array{Int64,1}

but

julia> f(Union{Missing,Array})
ERROR: MethodError: no method matching f(::Type{Union{Missing, Array}})
Closest candidates are:
  f(::Type{Union{Missing, T}}) where T at REPL[5]:1

which is consistent with

julia> Union{Missing,Array{Int,1}} isa (Type{Union{Missing, T}} where T)
true

julia> Union{Missing,Array} isa (Type{Union{Missing, T}} where T)
false

where I do not, however, understand why the latter is false.

And why should it be an UndefVarError? Isn't T uniquely defined here?

@mbauman
Copy link
Member

mbauman commented Feb 21, 2018

That looks like #26129.

@nalimilan
Copy link
Member

I think we should be able to get the expected behavior by doing the type computation manually inside a @pure function.

@vtjnash
Copy link
Member

vtjnash commented Feb 21, 2018

I implement some of that computation in inference, called "typesubtract". But it's not marked pure since I don't believe that function is pure.

iamed2 added a commit to JuliaDatabases/LibPQ.jl that referenced this issue Feb 27, 2018
iamed2 added a commit to JuliaDatabases/LibPQ.jl that referenced this issue Feb 27, 2018
@nalimilan
Copy link
Member

JuliaData/Missings.jl#82 changes Missings.T to use typesubtract. After it we'll no longer need this behavior. However there may be some inconsistencies to fix here anyway.

@JeffBezanson JeffBezanson added the types and dispatch Types, subtyping and method dispatch label Apr 3, 2018
@JeffBezanson
Copy link
Member

Looks like a duplicate of #24333.

@omus
Copy link
Member

omus commented Mar 19, 2019

Would it be reasonable for a call of f(Missing) given f(::Type{Union{Missing, T}}) where {T} = T to result in T == Union{}?

I realize that this isn't a UnionAll which is the original focus of this issue.

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

8 participants