Skip to content

Calling sizehint! with a UInt length parameter causes errors for some container types. #58531

@danielwpooleyivai

Description

@danielwpooleyivai

For some containers (such as Vector), this appears to be a non-issue.

A minimum working example:

d = Dict{UInt,String}()
sizehint!(d, UInt(1024))

Obviously this is easily worked-around, but could be an issue when running older Julia code with 1.11.
The resulting error indicates the issue is with UInt not being a valid type for Memory constructors:

ERROR: MethodError: no method matching Memory{UInt8}(::UndefInitializer, ::UInt64)
The type `Memory{UInt8}` exists, but no method is defined for this combination of argument types when trying to construct it.

Closest candidates are:
  GenericMemory{kind, T, addrspace}(::UndefInitializer, ::Tuple{Int64}) where {T, kind, addrspace}
   @ Core boot.jl:518
  GenericMemory{kind, T, addrspace}(::UndefInitializer, ::Int64) where {T, addrspace, kind}
   @ Core boot.jl:512
  Memory{T}(::AbstractVector{S}) where {T, S}
   @ Base genericmemory.jl:212
  ...

Stacktrace:
 [1] rehash!(h::Dict{UInt64, String}, newsz::UInt64)
   @ Base .\dict.jl:0
 [2] #sizehint!#423
   @ .\dict.jl:199 [inlined]
 [3] sizehint!(d::Dict{UInt64, String}, newsz::UInt64)
   @ Base .\dict.jl:193
 [4] top-level scope
   @ REPL[6]:1

(Version follows)

Julia Version 1.11.5
Commit 760b2e5b73 (2025-04-14 06:53 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 24 × AMD Ryzen 9 5900X 12-Core Processor
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, znver3)
Threads: 1 default, 0 interactive, 1 GC (on 24 virtual cores)

Metadata

Metadata

Assignees

No one assigned

    Labels

    collectionsData structures holding multiple items, e.g. sets

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions