Skip to content

Commit ad3769e

Browse files
authored
Base: make Tuple(::Pair) type-stable (#52650)
Fixes #52636
1 parent 90ae544 commit ad3769e

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

base/tuple.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ _totuple(::Type{Tuple}, itr, s...) = (collect(Iterators.rest(itr,s...))...,)
417417
_totuple(::Type{Tuple}, itr::Array) = (itr...,)
418418
_totuple(::Type{Tuple}, itr::SimpleVector) = (itr...,)
419419
_totuple(::Type{Tuple}, itr::NamedTuple) = (itr...,)
420+
_totuple(::Type{Tuple}, p::Pair) = (p.first, p.second)
420421
_totuple(::Type{Tuple}, x::Number) = (x,) # to make Tuple(x) inferable
421422

422423
end

test/tuple.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,3 +807,9 @@ namedtup = (;a=1, b=2, c=3)
807807
@test Val{Tuple{Vararg{T,4}} where T} === Val{Tuple{T,T,T,T} where T}
808808
@test Val{Tuple{Int64, Vararg{Int32,N}} where N} === Val{Tuple{Int64, Vararg{Int32}}}
809809
@test Val{Tuple{Int32, Vararg{Int64}}} === Val{Tuple{Int32, Vararg{Int64,N}} where N}
810+
811+
@testset "from Pair, issue #52636" begin
812+
pair = (1 => "2")
813+
@test (1, "2") == @inferred Tuple(pair)
814+
@test (1, "2") == @inferred Tuple{Int,String}(pair)
815+
end

0 commit comments

Comments
 (0)