From b0de4c629d9cf0cf0e755990d34bc64c8a96abf3 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Fri, 28 Sep 2018 13:43:39 -0400 Subject: [PATCH] fix #20872, handle UnionAll types in `which` --- base/reflection.jl | 10 +++++++--- test/reflection.jl | 8 ++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/base/reflection.jl b/base/reflection.jl index da407a73c82eb..066125fda10a9 100644 --- a/base/reflection.jl +++ b/base/reflection.jl @@ -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 @@ -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 """ diff --git a/test/reflection.jl b/test/reflection.jl index b1f5fecc9178f..db85f100af910 100644 --- a/test/reflection.jl +++ b/test/reflection.jl @@ -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)