Skip to content

Commit a4fbcfd

Browse files
committed
Restrict allowed ranges for ConcretizedSlice
1 parent e38def2 commit a4fbcfd

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/varname.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -871,10 +871,12 @@ end
871871
index_to_dict(i::Integer) = Dict(:type => "integer", :value => i)
872872
index_to_dict(r::UnitRange) = Dict(:type => "unitrange", :first => first(r), :last => last(r))
873873
index_to_dict(::Colon) = Dict(:type => "colon")
874-
index_to_dict(s::ConcretizedSlice{T,R}) where {T,R} = Dict(:type => "concretized_slice", :range => repr(s.range))
874+
index_to_dict(s::ConcretizedSlice{T,Base.OneTo{I}}) where {T,I} = Dict(:type => "concretized_slice", :oneto => s.range.stop)
875+
index_to_dict(::ConcretizedSlice{T,R}) where {T,R} = error("ConcretizedSlice with range type $(R) not supported")
875876
index_to_dict(t::Tuple) = Dict(:type => "tuple", :values => [index_to_dict(x) for x in t])
876877

877878
function dict_to_index(dict)
879+
# conversion needed because of the same reason as in dict_to_optic
878880
dict = Dict(Symbol(k) => v for (k, v) in dict)
879881
if dict[:type] == "integer"
880882
return dict[:value]
@@ -883,9 +885,11 @@ function dict_to_index(dict)
883885
elseif dict[:type] == "colon"
884886
return Colon()
885887
elseif dict[:type] == "concretized_slice"
886-
return ConcretizedSlice(eval(Meta.parse(dict[:range])))
888+
return ConcretizedSlice(Base.Slice(Base.OneTo(dict[:oneto])))
887889
elseif dict[:type] == "tuple"
888890
return tuple(map(dict_to_index, dict[:values])...)
891+
else
892+
error("Unknown index type: $(dict[:type])")
889893
end
890894
end
891895

@@ -909,6 +913,8 @@ function dict_to_optic(dict)
909913
return PropertyLens{Symbol(dict[:field])}()
910914
elseif dict[:type] == "composed"
911915
return dict_to_optic(dict[:outer]) dict_to_optic(dict[:inner])
916+
else
917+
error("Unknown optic type: $(dict[:type])")
912918
end
913919
end
914920

0 commit comments

Comments
 (0)