Skip to content

Commit

Permalink
fix isvatuple to properly handle UnionAlls (JuliaLang#27018)
Browse files Browse the repository at this point in the history
* fix isvatuple to properly handle UnionAlls

* add tests for JuliaLang#27018
  • Loading branch information
jrevels committed May 8, 2018
1 parent 024bfdb commit b19ba88
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
10 changes: 9 additions & 1 deletion base/essentials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,15 @@ function isvarargtype(@nospecialize(t))
return isa(t, DataType) && (t::DataType).name === _va_typename
end

isvatuple(t::DataType) = (n = length(t.parameters); n > 0 && isvarargtype(t.parameters[n]))
function isvatuple(@nospecialize(t))
t = unwrap_unionall(t)
if isa(t, DataType)
n = length(t.parameters)
return n > 0 && isvarargtype(t.parameters[n])
end
return false
end

function unwrapva(@nospecialize(t))
# NOTE: this returns a related type, but it's NOT a subtype of the original tuple
t2 = unwrap_unionall(t)
Expand Down
10 changes: 10 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6051,3 +6051,13 @@ g2_23206(::Tuple{Type{Int}}) = 1
let x26739 = Int[1]
@test eval(:(identity.($x26739))) == x26739
end

# issue #27018
@test Base.isvatuple(Tuple{Float64,Vararg{Int}})
@test Base.isvatuple(Tuple{T,Vararg{Int}} where T)
@test Base.isvatuple(Tuple{Int,Int,Vararg{Int,N}} where N)
@test Base.isvatuple(Tuple{T,S,Vararg{T}} where T<:S where S)
@test Base.isvatuple(Tuple{T,S,Vararg{T,3}} where T<:S where S)
@test !Base.isvatuple(Tuple{Float64,Vararg{Int,1}})
@test !Base.isvatuple(Tuple{T,Vararg{Int,2}} where T)
@test !Base.isvatuple(Tuple{Int,Int,Vararg{Int,2}})

0 comments on commit b19ba88

Please sign in to comment.