Hi all. I’m trying to pass an argument of type Dict{String, String}
to a function with signature Dict{String, Any}
, e.g.,
function foo(x::Dict{String, Any})
x
end
When I invoke it like so:
foo(Dict("bar"=>"baz"))
I get
ERROR: MethodError: no method matching foo(::Dict{String,String})
Closest candidates are:
foo(::Dict{String,Any}) at REPL[18]:2
I’m confused by this. Doesn’t a Dict{String, String}
fall under the Dict{String, Any}
category? I guess this is related to the disclaimer in Parametric Composite Types, namely:
This last point is very important: even though
Float64 <: Real
we DO NOT havePoint{Float64} <: Point{Real}
.
What would be the correct thing to do here? I expect to pass Dict
s keyed by String
with arbitrary value types to foo
(think JSON objects), but I don’t want foo
to fail if the Dict
happens to have the same type for all its values.