-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Define eltype(::Type{Union{}}) = Union{}
?
#20140
Comments
The problem you run into is that your inferred result becomes |
This seems to be a change from 0.5. I came across it while trying to get Lint to work on 0.6. 0.5: julia> eltype(Union{})
Union{} 0.6: julia> eltype(Union{})
ERROR: MethodError: eltype(::Type{Union{}}) is ambiguous. Candidates:
eltype{E,T<:Tuple{Vararg{E,N} where N}}(::Type{T}) in Base at tuple.jl:52
eltype{E,A<:(AbstractArray{E,N} where N)}(::Type{A}) in Base
eltype{T<:AbstractString}(::Type{T}) in Base at strings/basic.jl:54
eltype{T<:Base.Dates.Period}(::Type{T}) in Base.Dates at dates/types.jl:238
eltype{T<:Number}(::Type{T}) in Base at number.jl:28 @Keno, I don't understand what you mean. |
|
OK, so this change would pessimize type inference in certain situations, and was therefore intentional? |
It's a koan: "if you have no object at all, is it iterable?" I would say no. |
We should get into the habit of implementing these policy decisions via informative error messages. As it is now, this is an ambiguity error which leaves the intentionality...ambiguous. See #20568. |
Currently,
eltype(Union{})
throws a method ambiguity error. Since there is nothing of typeUnion{}
, it is natural that are no objects that are elements of objects of typeUnion{}
, so the definitioneltype(::Type{Union{}}) = Union{}
makes sense.The text was updated successfully, but these errors were encountered: