@@ -141,20 +141,19 @@ foldtree(op, init, ex::Expr) =
141141
142142need_dynamic_optic (ex) =
143143 foldtree (false , ex) do yes, x
144- yes || x === :end || (x === :begin ) || x === :_
144+ yes || x ∈ ( :end , :begin , Expr ( :end ), Expr ( :begin ), :_ )
145145 end
146146
147147replace_underscore (ex, to) = postwalk (x -> x === :_ ? to : x, ex)
148148
149149function lower_index (collection:: Symbol , index, dim)
150- index = MacroTools. replace (
151- index, :end ,
152- dim === nothing ? :($ (Base. lastindex)($ collection)) : :($ (Base. lastindex)($ collection, $ dim))
153- )
154- index = MacroTools. replace (
155- index, :begin ,
156- dim === nothing ? :($ (Base. firstindex)($ collection)) : :($ (Base. firstindex)($ collection, $ dim))
157- )
150+ lasti = dim === nothing ? :($ (Base. lastindex)($ collection)) : :($ (Base. lastindex)($ collection, $ dim))
151+ firsti = dim === nothing ? :($ (Base. firstindex)($ collection)) : :($ (Base. firstindex)($ collection, $ dim))
152+ index = MacroTools. replace (index, :end , lasti)
153+ index = MacroTools. replace (index, :begin , firsti)
154+ # New syntax for begin/end in indexing expression, see https://github.com/JuliaLang/julia/pull/57368
155+ index = MacroTools. replace (index, Expr (:end ), lasti)
156+ index = MacroTools. replace (index, Expr (:begin ), firsti)
158157end
159158
160159_secondarg (_, x) = x
0 commit comments