Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/sugar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ foldtree(op, init, ex::Expr) =

need_dynamic_optic(ex) =
foldtree(false, ex) do yes, x
yes || x === :end || (x === :begin) || x === :_
yes || x === :end || x === :begin || x == Expr(:end) || x == Expr(:begin) || x === :_
end

replace_underscore(ex, to) = postwalk(x -> x === :_ ? to : x, ex)
Expand All @@ -155,6 +155,15 @@ function lower_index(collection::Symbol, index, dim)
index, :begin,
dim === nothing ? :($(Base.firstindex)($collection)) : :($(Base.firstindex)($collection, $dim))
)
# New syntax for begin/end in indexing expression, see https://github.com/JuliaLang/julia/pull/57368
index = MacroTools.replace(
index, Expr(:end),
dim === nothing ? :($(Base.lastindex)($collection)) : :($(Base.lastindex)($collection, $dim))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same replacement as for :end above, right? Then – for clarity – it should probably be defined once and assigned to a variable, with two short replace() calls following it.

)
index = MacroTools.replace(
index, Expr(:begin),
dim === nothing ? :($(Base.firstindex)($collection)) : :($(Base.firstindex)($collection, $dim))
)
end

_secondarg(_, x) = x
Expand Down
Loading