Skip to content

Commit 7a87048

Browse files
authored
Restrict arg of sizehint!(::Dict, n) to Integer (#58533)
But also allow other types of integers than Int. Closes #58531 (for Dict)
1 parent e984c57 commit 7a87048

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

base/dict.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ end
190190
return h
191191
end
192192

193-
function sizehint!(d::Dict{T}, newsz; shrink::Bool=true) where T
193+
function sizehint!(d::Dict{T}, newsz::Integer; shrink::Bool=true) where T
194+
newsz = Int(newsz)::Int
194195
oldsz = length(d.slots)
195196
# limit new element count to max_values of the key type
196197
newsz = min(max(newsz, length(d)), max_values(T)::Int)

test/dict.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,14 @@ end
294294
@test eq(Dict{Int,Int}(), Dict{AbstractString,AbstractString}())
295295
end
296296

297+
@testset "sizehint!" begin
298+
d = Dict()
299+
sizehint!(d, UInt(3))
300+
@test d == Dict()
301+
sizehint!(d, 5)
302+
@test isempty(d)
303+
end
304+
297305
@testset "equality special cases" begin
298306
@test Dict(1=>0.0) == Dict(1=>-0.0)
299307
@test !isequal(Dict(1=>0.0), Dict(1=>-0.0))

0 commit comments

Comments
 (0)