@@ -141,20 +141,19 @@ foldtree(op, init, ex::Expr) =
141
141
142
142
need_dynamic_optic (ex) =
143
143
foldtree (false , ex) do yes, x
144
- yes || x === :end || (x === :begin ) || x === :_
144
+ yes || x ∈ ( :end , :begin , Expr ( :end ), Expr ( :begin ), :_ )
145
145
end
146
146
147
147
replace_underscore (ex, to) = postwalk (x -> x === :_ ? to : x, ex)
148
148
149
149
function 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)
158
157
end
159
158
160
159
_secondarg (_, x) = x
0 commit comments