Skip to content

Commit f99e6bf

Browse files
authored
fix sorting for iterables that define copymutable (#52086)
1 parent f31cd8a commit f99e6bf

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

base/sort.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,7 +1500,7 @@ function sort(v; kws...)
15001500
size = IteratorSize(v)
15011501
size == HasShape{0}() && throw(ArgumentError("$v cannot be sorted"))
15021502
size == IsInfinite() && throw(ArgumentError("infinite iterator $v cannot be sorted"))
1503-
sort!(copymutable(v); kws...)
1503+
sort!(collect(v); kws...)
15041504
end
15051505
sort(v::AbstractVector; kws...) = sort!(copymutable(v); kws...) # for method disambiguation
15061506
sort(::AbstractString; kws...) =
@@ -1512,7 +1512,7 @@ function sort(x::NTuple{N}; lt::Function=isless, by::Function=identity,
15121512
rev::Union{Bool,Nothing}=nothing, order::Ordering=Forward) where N
15131513
o = ord(lt,by,rev,order)
15141514
if N > 9
1515-
v = sort!(copymutable(x), DEFAULT_STABLE, o)
1515+
v = sort!(collect(x), DEFAULT_STABLE, o)
15161516
tuple((v[i] for i in 1:N)...)
15171517
else
15181518
_sort(x, o)

test/sorting.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,11 @@ end
559559

560560
@test_throws ArgumentError sort("string")
561561
@test_throws ArgumentError("1 cannot be sorted") sort(1)
562+
563+
@test sort(Set((1, 3, 6))) == [1, 3, 6]
564+
@test sort(Dict((1=>9, 3=>2, 6=>5))) == [1=>9, 3=>2, 6=>5]
565+
@test sort(keys(Dict((1=>2, 3=>5, 6=>9)))) == [1, 3, 6]
566+
@test sort(values(Dict((1=>9, 3=>2, 6=>5)))) == [2, 5, 9]
562567
end
563568

564569
@testset "sort!(::AbstractVector{<:Integer}) with short int range" begin

0 commit comments

Comments
 (0)