Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid piracy in cat #254

Merged
merged 2 commits into from
Nov 30, 2022
Merged

Avoid piracy in cat #254

merged 2 commits into from
Nov 30, 2022

Conversation

jishnub
Copy link
Member

@jishnub jishnub commented Nov 24, 2022

Currently, on master

julia> cat(dims=1)
Any[]

julia> using StructArrays

julia> cat(dims=1)
ERROR: MethodError: reducing over an empty collection is not allowed; consider supplying `init` to the reducer
Stacktrace:
  [1] reduce_empty(op::Base.MappingRF{typeof(eltype), Base.BottomRF{typeof(promote_type)}}, #unused#::Type{Union{}})
    @ Base ./reduce.jl:356
  [2] reduce_empty_iter(op::Base.MappingRF{typeof(eltype), Base.BottomRF{typeof(promote_type)}}, itr::Tuple{}, #unused#::Base.HasEltype)
    @ Base ./reduce.jl:379
  [3] reduce_empty_iter(op::Base.MappingRF{typeof(eltype), Base.BottomRF{typeof(promote_type)}}, itr::Tuple{})
    @ Base ./reduce.jl:378
  [4] foldl_impl(op::Base.MappingRF{typeof(eltype), Base.BottomRF{typeof(promote_type)}}, nt::Base._InitialValue, itr::Tuple{})
    @ Base ./reduce.jl:49
  [5] mapfoldl_impl(f::typeof(eltype), op::typeof(promote_type), nt::Base._InitialValue, itr::Tuple{})
    @ Base ./reduce.jl:44
  [6] mapfoldl(f::Function, op::Function, itr::Tuple{}; init::Base._InitialValue)
    @ Base ./reduce.jl:170
  [7] mapfoldl
    @ ./reduce.jl:170 [inlined]
  [8] #mapreduce#263
    @ ./reduce.jl:302 [inlined]
  [9] mapreduce(f::Function, op::Function, itr::Tuple{})
    @ Base ./reduce.jl:302
 [10] cat(; kwargs::Base.Pairs{Symbol, Int64, Tuple{Symbol}, NamedTuple{(:dims,), Tuple{Int64}}})
    @ StructArrays ~/Dropbox/JuliaPackages/StructArrays.jl/src/structarray.jl:450
 [11] top-level scope
    @ REPL[2]:1

This PR fixes this by avoiding the accidental type piracy

@piever
Copy link
Collaborator

piever commented Nov 30, 2022

Well spotted!

@piever piever merged commit e2fe9a2 into JuliaArrays:master Nov 30, 2022
@jishnub jishnub deleted the catpiracy branch November 30, 2022 10:30
@piever piever mentioned this pull request Nov 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants