Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

[bug] Type assert of filter fails for empty `CircularBuffer`

Aperta
#810 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
julia
Ambito
data

Direzione di ricerca

Inizia dal dispatch che fallisce in Base ./array.jl:2492 e analizza il comportamento di filter di CircularBuffer. Riproduci i casi di un buffer vuoto per i tipi di elemento Any e Integer, quindi confrontali con il filtraggio di un Vector vuoto. Il lavoro è completato quando il filtraggio di un CircularBuffer vuoto non solleva più l’errore di asserzione di tipo segnalato e corrisponde al comportamento documentato di Vector.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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:

  1. Specify the filter method for CircularBuffer to use the method with Array on the underlining buffer and not AbstractArray on the struct,
  2. Overwrite the filter method and make it return a new CircularBuffer.

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?

Lingua principale
Julia
Stelle
747
Fork
261
Merge medio
12g 6h
PR unite (30g)
1

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di JuliaCollections/DataStructures.jl

Tutte le issue di JuliaCollections/DataStructures.jl

Issue simili

Altre issue su Julia

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.