Skip to content

Commit

Permalink
Handle ellipsis in Tuple{} (Fix #81)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyichao committed May 6, 2015
1 parent d013435 commit ccae986
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,15 @@ function _compat(ex::Expr)
elseif ex.head == :curly
f = ex.args[1]
if VERSION < v"0.4.0-dev+4319" && f == :Tuple
ex = Expr(:tuple, ex.args[2:end]...)
args = ex.args[2:end]
has_ellipsis = any(args) do arg
isa(arg, Expr) && (arg.head == :...)
end
ex = if has_ellipsis
Expr(:call, TopNode(:tuple), args...)
else
Expr(:tuple, args...)
end
end
end
return Expr(ex.head, map(_compat, ex.args)...)
Expand Down
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ if VERSION < v"0.4.0-dev+4319"
@test @compat Tuple{Int, Tuple{Float64}} == (Int, (Float64,))
@test @compat Tuple{Int, Tuple{Float64, Char}} == (Int, (Float64, Char))
@test @compat Tuple{Int, Vararg{Float64}} == (Int, Float64...)
# Issue 81
a81 = [Int, Int]
b81 = (Int, Int)
@test @compat Tuple{a81..., Vararg{Float64}} == (Int, Int, Float64...)
@test @compat Tuple{b81..., Vararg{Float64}} == (Int, Int, Float64...)
end

# Ensure eachindex iterates over the whole array
Expand Down

0 comments on commit ccae986

Please sign in to comment.