From 81ae9eab4166c02d93cc1a10353b747941e72df3 Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Thu, 23 Mar 2023 10:20:16 +0100 Subject: [PATCH] Type-assert the value type in getindex(::AbstractDict, key) Closes https://github.com/JuliaCollections/OrderedCollections.jl/issues/101 --- base/abstractdict.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/base/abstractdict.jl b/base/abstractdict.jl index c523a25cecd3f..ab1ad2464cb4c 100644 --- a/base/abstractdict.jl +++ b/base/abstractdict.jl @@ -536,12 +536,12 @@ function hash(a::AbstractDict, h::UInt) hash(hv, h) end -function getindex(t::AbstractDict, key) +function getindex(t::AbstractDict{<:Any,V}, key) where V v = get(t, key, secret_table_token) if v === secret_table_token throw(KeyError(key)) end - return v + return v::V end # t[k1,k2,ks...] is syntactic sugar for t[(k1,k2,ks...)]. (Note