Skip to content

zero-dimensional reverse and reverse! for AbstractArray throw #58085

Closed
@nsajko

Description

@nsajko

Not a regression, the bug was here ever since the subfeature was introduced in v1.6 with PR #37367.

julia> a = fill(7)
0-dimensional Array{Int64, 0}:
7

julia> reverse!(a)
ERROR: ArgumentError: reducing with add_sum over an empty collection of element type Union{} is not allowed.
You may be able to prevent this error by supplying an `init` value to the reducer.
Stacktrace:
  [1] _empty_reduce_error(f::Any, T::Type)
    @ Base ./reduce.jl:320
  [2] reduce_empty(::typeof(Base.add_sum), ::Core.TypeofBottom)
    @ Base ./reduce.jl:351
  [3] reduce_empty(op::Base.BottomRF{typeof(Base.add_sum)}, ::Type{Union{}})
    @ Base ./reduce.jl:360
  [4] reduce_empty_iter
    @ ./reduce.jl:384 [inlined]
  [5] reduce_empty_iter
    @ ./reduce.jl:383 [inlined]
  [6] foldl_impl(op::Base.BottomRF{typeof(Base.add_sum)}, nt::Base._InitialValue, itr::Tuple{})
    @ Base ./reduce.jl:49
  [7] mapfoldl_impl(f::typeof(identity), op::typeof(Base.add_sum), nt::Base._InitialValue, itr::Tuple{})
    @ Base ./reduce.jl:44
  [8] mapfoldl(f::Function, op::Function, itr::Tuple{}; init::Base._InitialValue)
    @ Base ./reduce.jl:175
  [9] mapfoldl
    @ ./reduce.jl:175 [inlined]
 [10] mapreduce
    @ ./reduce.jl:307 [inlined]
 [11] sum(f::Function, a::Tuple{})
    @ Base ./reduce.jl:535
 [12] sum(a::Tuple{}; kw::@Kwargs{})
    @ Base ./reduce.jl:564
 [13] _reverse!(A::Array{Int64, 0}, dims::Tuple{})
    @ Base ./arraymath.jl:77
 [14] _reverse!(A::Array{Int64, 0}, ::Colon)
    @ Base ./arraymath.jl:71
 [15] reverse!(A::Array{Int64, 0}; dims::Function)
    @ Base ./arraymath.jl:70
 [16] top-level scope
    @ REPL[4]:1

julia> reverse(a)
ERROR: ArgumentError: reducing with add_sum over an empty collection of element type Union{} is not allowed.
You may be able to prevent this error by supplying an `init` value to the reducer.
Stacktrace:
  [1] _empty_reduce_error(f::Any, T::Type)
    @ Base ./reduce.jl:320
  [2] reduce_empty(::typeof(Base.add_sum), ::Core.TypeofBottom)
    @ Base ./reduce.jl:351
  [3] reduce_empty(op::Base.BottomRF{typeof(Base.add_sum)}, ::Type{Union{}})
    @ Base ./reduce.jl:360
  [4] reduce_empty_iter
    @ ./reduce.jl:384 [inlined]
  [5] reduce_empty_iter
    @ ./reduce.jl:383 [inlined]
  [6] foldl_impl(op::Base.BottomRF{typeof(Base.add_sum)}, nt::Base._InitialValue, itr::Tuple{})
    @ Base ./reduce.jl:49
  [7] mapfoldl_impl(f::typeof(identity), op::typeof(Base.add_sum), nt::Base._InitialValue, itr::Tuple{})
    @ Base ./reduce.jl:44
  [8] mapfoldl(f::Function, op::Function, itr::Tuple{}; init::Base._InitialValue)
    @ Base ./reduce.jl:175
  [9] mapfoldl
    @ ./reduce.jl:175 [inlined]
 [10] mapreduce
    @ ./reduce.jl:307 [inlined]
 [11] sum(f::Function, a::Tuple{})
    @ Base ./reduce.jl:535
 [12] sum(a::Tuple{}; kw::@Kwargs{})
    @ Base ./reduce.jl:564
 [13] _reverse!(A::Array{Int64, 0}, dims::Tuple{})
    @ Base ./arraymath.jl:77
 [14] _reverse!(A::Array{Int64, 0}, ::Colon)
    @ Base ./arraymath.jl:71
 [15] reverse!(A::Array{Int64, 0}; dims::Function)
    @ Base ./arraymath.jl:70
 [16] _reverse(A::Array{Int64, 0}, dims::Function)
    @ Base ./arraymath.jl:60
 [17] reverse(A::Array{Int64, 0}; dims::Function)
    @ Base ./arraymath.jl:59
 [18] top-level scope
    @ REPL[5]:1

Metadata

Metadata

Assignees

Labels

arrays[a, r, r, a, y, s]collectionsData structures holding multiple items, e.g. sets

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions