-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Closed
Labels
types and dispatchTypes, subtyping and method dispatchTypes, subtyping and method dispatch
Description
julia> foo{N}(::Val{N}, ::Type{Val{N}}) = true
foo (generic function with 1 method)
julia> methods(foo, (Val{0}, Type{Val{N}} where N))
# 0 methods for generic function "foo":but for N==0, the one method we have actually does match. This can lead inference astray:
julia> foo{N1,N2}(::Val{N1}, ::Type{Val{N2}}) = "mismatch"
foo (generic function with 2 methods)
julia> bar(n) = foo(Val{0}(), Val{n})
bar (generic function with 1 method)
julia> bar(0)
true
julia> Base.return_types(bar, (Int,))
1-element Array{Any,1}:
StringThat should of course be Union{Bool, String}, but inference only sees the second method of foo.
This affects e.g. ntuple and rdims:
julia> Base.return_types(ntuple, (typeof(identity), Type{Val{N}} where N))
1-element Array{Any,1}:
Tuple{Int64,Int64,Int64,Int64,Int64,Int64,Int64,Int64,Int64,Int64,Int64,Int64,Int64,Int64,Vararg{Any,N}} where NMetadata
Metadata
Assignees
Labels
types and dispatchTypes, subtyping and method dispatchTypes, subtyping and method dispatch