Accessors.jl icon indicating copy to clipboard operation
Accessors.jl copied to clipboard

DimensionMismatch after slicing

Open jariji opened this issue 3 months ago • 1 comments

I was expecting this to work.

julia> let obj  = ['h', 'e', 'l', 'l', 'o']
           @modify(reverse(obj)) do x
               x[1:3]
           end
       
       end
ERROR: DimensionMismatch: array could not be broadcast to match destination
Stacktrace:
 [1] check_broadcast_shape
   @ ./broadcast.jl:552 [inlined]
 [2] check_broadcast_axes
   @ ./broadcast.jl:555 [inlined]
 [3] instantiate
   @ ./broadcast.jl:310 [inlined]
 [4] materialize!
   @ ./broadcast.jl:883 [inlined]
 [5] materialize!
   @ ./broadcast.jl:880 [inlined]
 [6] set(x::Vector{Char}, ::typeof(reverse), v::Vector{Char})
   @ Accessors ~/.julia/packages/Accessors/8Y4uq/src/functionlenses.jl:96
 [7] _modify(f::var"#153#154", obj::Vector{Char}, optic::typeof(reverse), ::Accessors.SetBased)
   @ Accessors ~/.julia/packages/Accessors/8Y4uq/src/optics.jl:209
 [8] modify(f::Function, obj::Vector{Char}, optic::typeof(reverse))
   @ Accessors ~/.julia/packages/Accessors/8Y4uq/src/optics.jl:189
 [9] top-level scope

jariji avatar Sep 12 '25 22:09 jariji

Heh, I guess you are right, it makes sense for set(reverse) to allow changing the array length. PRs to fix bugs / add missing functionality like this are welcome!

aplavin avatar Sep 13 '25 00:09 aplavin