Skip to content

Commit 695fedb

Browse files
Improve typejoin involving an empty tuple (#24485)
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 7c2a42a commit 695fedb

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

base/promotion.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,14 @@ function typejoin(@nospecialize(a), @nospecialize(b))
3434
end
3535
ap, bp = a.parameters, b.parameters
3636
lar = length(ap)::Int; lbr = length(bp)::Int
37+
if lar == 0
38+
return Tuple{Vararg{tailjoin(bp,1)}}
39+
end
40+
if lbr == 0
41+
return Tuple{Vararg{tailjoin(ap,1)}}
42+
end
3743
laf, afixed = full_va_len(ap)
3844
lbf, bfixed = full_va_len(bp)
39-
if lar==0 || lbr==0
40-
return Tuple
41-
end
4245
if laf < lbf
4346
if isvarargtype(ap[lar]) && !afixed
4447
c = Vector{Any}(laf)

test/core.jl

Lines changed: 1 addition & 0 deletions
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)