Skip to content

Commit 19aedfd

Browse files
committed
Allow for proposed new parsing of array[end] in Accessors
1 parent 6d0d965 commit 19aedfd

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/sugar.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ foldtree(op, init, ex::Expr) =
141141

142142
need_dynamic_optic(ex) =
143143
foldtree(false, ex) do yes, x
144-
yes || x === :end || (x === :begin) || x === :_
144+
yes || x === :end || x === :begin || x == Expr(:end) || x == Expr(:begin) || x === :_
145145
end
146146

147147
replace_underscore(ex, to) = postwalk(x -> x === :_ ? to : x, ex)
@@ -155,6 +155,15 @@ function lower_index(collection::Symbol, index, dim)
155155
index, :begin,
156156
dim === nothing ? :($(Base.firstindex)($collection)) : :($(Base.firstindex)($collection, $dim))
157157
)
158+
# New syntax for begin/end in indexing expression, see https://github.com/JuliaLang/julia/pull/57368
159+
index = MacroTools.replace(
160+
index, Expr(:end),
161+
dim === nothing ? :($(Base.lastindex)($collection)) : :($(Base.lastindex)($collection, $dim))
162+
)
163+
index = MacroTools.replace(
164+
index, Expr(:begin),
165+
dim === nothing ? :($(Base.firstindex)($collection)) : :($(Base.firstindex)($collection, $dim))
166+
)
158167
end
159168

160169
_secondarg(_, x) = x

0 commit comments

Comments
 (0)