Skip to content

Commit 940f59e

Browse files
committed
Improve typejoin involving an empty tuple
Don't just return `Tuple` when joining an empty and a non-empty tuple, instead return the appropriate vararg tuple, similar to otherwise joining tuples of unequal length.
1 parent ce76e08 commit 940f59e

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

base/promotion.jl

+6-3
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,14 @@ function typejoin(@nospecialize(a), @nospecialize(b))
2929
end
3030
ap, bp = a.parameters, b.parameters
3131
lar = length(ap)::Int; lbr = length(bp)::Int
32+
if lar == 0
33+
return Tuple{Vararg{tailjoin(bp,1)}}
34+
end
35+
if lbr == 0
36+
return Tuple{Vararg{tailjoin(ap,1)}}
37+
end
3238
laf, afixed = full_va_len(ap)
3339
lbf, bfixed = full_va_len(bp)
34-
if lar==0 || lbr==0
35-
return Tuple
36-
end
3740
if laf < lbf
3841
if isvarargtype(ap[lar]) && !afixed
3942
c = Vector{Any}(laf)

test/core.jl

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ Type{Integer} # cache this
106106
Tuple{Int8,Vararg{Integer}})
107107
@test Base.typeseq(typejoin(Union{Int,AbstractString},Int), Union{Int,AbstractString})
108108
@test Base.typeseq(typejoin(Union{Int,AbstractString},Int8), Any)
109+
@test typejoin(Tuple{}, Tuple{Int}) == Tuple{Vararg{Int}}
109110

110111
# typejoin associativity
111112
abstract type Foo____{K} end

0 commit comments

Comments
 (0)