You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
julia> d1 =Dict(:a=>3, :b=>2.0)
Dict{Symbol, Real} with 2 entries::a=>3:b=>2.0
julia>functionf(d1)
@unpack a = d1
a
end
f (generic function with 1 method)
julia>@code_typedf(d1)
CodeInfo(
1 ─ %1= invoke Base.getindex(d1::Dict{Symbol, Real}, :a::Symbol)::Real
└── return%1
) => Real
In this case, if I know that a must be an Int, I might want to specify this as a::Int in the @unpack, but the following doesn't work:
julia>functionf(d1)
@unpack a::Int= d1
a
end
f (generic function with 1 method)
julia>f(d1)
ERROR: KeyError: key :Int not found
Stacktrace:
[1] getindex(h::Dict{Symbol, Real}, key::Symbol)
@ Base ./dict.jl:484
[2] unpack
@ ~/.julia/packages/UnPack/EkESO/src/UnPack.jl:35 [inlined]
[3] macro expansion
@ ~/.julia/packages/UnPack/EkESO/src/UnPack.jl:101 [inlined]
[4] f(d1::Dict{Symbol, Real})
@ Main ./REPL[290]:2
[5] top-level scope
@ REPL[291]:1
The text was updated successfully, but these errors were encountered:
Thanks! Yes that would be a good feature, PR welcome.
Work-arounds:
julia>functionf(d1)
local a::Int@unpack a = d1
a
end
f (generic function with 1 method)
julia>functionf(d1)
(;a::Int) = d1
a
end
f (generic function with 1 method)
E.g.
In this case, if I know that
a
must be anInt
, I might want to specify this asa::Int
in the@unpack
, but the following doesn't work:The text was updated successfully, but these errors were encountered: