Skip to content

Wrongly empty typeintersect if a TypeVar needs to fixed to a non-type #20869

@martinholters

Description

@martinholters
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}:
 String

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

Metadata

Metadata

Assignees

Labels

types and dispatchTypes, subtyping and method dispatch

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions