From 98ad324416b8138558388e44c10478d9db6632da Mon Sep 17 00:00:00 2001 From: Jakob Peters Date: Sun, 24 Nov 2024 15:38:50 -0800 Subject: [PATCH] Fix type stability of `ReadEachIterator` Its `eltype` method had an incorrect type declaration. --- base/io.jl | 2 +- test/read.jl | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/base/io.jl b/base/io.jl index 83a215d6359fc..e4f56d6d87f92 100644 --- a/base/io.jl +++ b/base/io.jl @@ -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() diff --git a/test/read.jl b/test/read.jl index 99903d92d270f..fc643821e8974 100644 --- a/test/read.jl +++ b/test/read.jl @@ -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()