Skip to content

Commit

Permalink
fix #20872, handle UnionAll types in which
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Sep 29, 2018
1 parent aa559c4 commit b0de4c6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
10 changes: 7 additions & 3 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ function to_tuple_type(@nospecialize(t))
t = Tuple{t...}
end
if isa(t,Type) && t<:Tuple
for p in t.parameters
for p in unwrap_unionall(t).parameters
if !(isa(p,Type) || isa(p,TypeVar))
error("argument tuple type must contain only types")
end
Expand All @@ -660,8 +660,12 @@ end

function signature_type(@nospecialize(f), @nospecialize(args))
f_type = isa(f, Type) ? Type{f} : typeof(f)
arg_types = isa(args, Type) ? args.parameters : args
return Tuple{f_type, arg_types...}
if isa(args, Type)
u = unwrap_unionall(args)
return rewrap_unionall(Tuple{f_type, u.parameters...}, args)
else
return Tuple{f_type, args...}
end
end

"""
Expand Down
8 changes: 8 additions & 0 deletions test/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -797,3 +797,11 @@ end
@test !(:Test in names(M26267, all=true, imported=false))
@test :Test in names(M26267, all=true, imported=true)
@test :Test in names(M26267, all=false, imported=true)

# issue #20872
f20872(::Val{N}, ::Val{N}) where {N} = true
f20872(::Val, ::Val) = false
@test which(f20872, Tuple{Val{N},Val{N}} where N).sig == Tuple{typeof(f20872), Val{N}, Val{N}} where N
@test which(f20872, Tuple{Val,Val}).sig == Tuple{typeof(f20872), Val, Val}
@test which(f20872, Tuple{Val,Val{N}} where N).sig == Tuple{typeof(f20872), Val, Val}
@test_throws ErrorException which(f20872, Tuple{Any,Val{N}} where N)

0 comments on commit b0de4c6

Please sign in to comment.