JuliaCollections / JuliaCollections/DataStructures.jl
[bug] Type assert of filter fails for empty `CircularBuffer`
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 745
- Forks
- 261
- PR merge metrics
- No merged PRs in 30d
Description
Replicate
julia> cb = CircularBuffer(1)
> 0-element CircularBuffer{Any}
julia> filter(s -> s < 3, cb)
ERROR: TypeError: in typeassert, expected AbstractArray{Bool}, got a value of type Vector{Any}
Stacktrace:
[1] filter(f::var"#25#26", a::CircularBuffer{Any})
@ Base ./array.jl:2492
[2] top-level scope
@ REPL[27]:1
Specifying the eltype does not fix the issue
julia> cb = CircularBuffer{Integer}(1)
> 0-element CircularBuffer{Integer}
julia> filter(s -> s < 3, cb)
ERROR: TypeError: in typeassert, expected AbstractArray{Bool}, got a value of type Vector{Any}
Stacktrace:
[1] filter(f::var"#39#40", a::CircularBuffer{Integer})
@ Base ./array.jl:2492
[2] top-level scope
@ REPL[37]:1
Desired behaviour
It should behave the same way as with a Vector type.
julia> filter(s -> s < 3, [])
> Any[]
Possible solution
Since filter, returns a Vector type for CircularBuffer there are two solutions that both produce an ideologically different ouput:
- Specify the
filtermethod forCircularBufferto use the method withArrayon the underlining buffer and notAbstractArrayon the struct, - Overwrite the
filtermethod and make it return a newCircularBuffer.
I would think that the second option is the way to go since it would be easy for the user to use the method outputing Vector on demand.
Can you assign me?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the failing dispatch shown at Base ./array.jl:2492 and inspect CircularBuffer's filter behavior. Reproduce the empty-buffer cases for Any and Integer element types, then compare them with filtering an empty Vector. Done means filtering an empty CircularBuffer no longer raises the reported type assertion error and matches the documented Vector behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100