Skip to content

Commit

Permalink
Fix type stability of ReadEachIterator
Browse files Browse the repository at this point in the history
Its `eltype` method had an incorrect type declaration.
  • Loading branch information
jakobjpeters committed Nov 24, 2024
1 parent 0bedaae commit 98ad324
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,7 @@ readeach(stream::IOT, T::Type) where IOT<:IO = ReadEachIterator{T,IOT}(stream)
iterate(itr::ReadEachIterator{T}, state=nothing) where T =
eof(itr.stream) ? nothing : (read(itr.stream, T), nothing)

eltype(::Type{ReadEachIterator{T}}) where T = T
eltype(::Type{<:ReadEachIterator{T}}) where T = T

IteratorSize(::Type{<:ReadEachIterator}) = SizeUnknown()

Expand Down
2 changes: 2 additions & 0 deletions test/read.jl
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ for (name, f) in l
verbose && println("$name readeach...")
@test collect(readeach(io(), Char)) == Vector{Char}(text)
@test collect(readeach(io(), UInt8)) == Vector{UInt8}(text)
@test eltype(readeach(io(), Char)) <: Char
@test eltype(readeach(io(), UInt8)) <: UInt8

cleanup()

Expand Down

0 comments on commit 98ad324

Please sign in to comment.