File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -98,6 +98,33 @@ julia> getvalue(vals, @varname(x[2][1]))
9898ERROR: getvalue: x[2][1] was not found in the values provided
9999[...]
100100```
101+
102+ Dictionaries can present ambiguous cases where the same variable is specified
103+ twice at different levels. In such a situation, `getvalue` attempts to find an
104+ exact match, and if that fails it returns the value with the most specific key.
105+
106+ !!! note
107+ It is the user's responsibility to avoid such cases by ensuring that the
108+ dictionary passed in does not contain the same value specified multiple
109+ times.
110+
111+ ```jldoctest
112+ julia> vals = Dict(@varname(x) => [[1.0]], @varname(x[1]) => [2.0]);
113+
114+ julia> # Here, the `x[1]` key is not used because `x` is an exact match.
115+ getvalue(vals, @varname(x))
116+ 1-element Vector{Vector{Float64}}:
117+ [1.0]
118+
119+ julia> # Likewise, the `x` key is not used because `x[1]` is an exact match.
120+ getvalue(vals, @varname(x[1]))
121+ 1-element Vector{Float64}:
122+ 2.0
123+
124+ julia> # No exact match, so the most specific key, i.e. `x[1]`, is used.
125+ getvalue(vals, @varname(x[1][1]))
126+ 2.0
127+ ```
101128"""
102129function getvalue (vals:: NamedTuple , vn:: VarName{sym} ) where {sym}
103130 optic = getoptic (vn)
You can’t perform that action at this time.
0 commit comments