Skip to content

Commit

Permalink
fix #55389: type-unstable join (#55395)
Browse files Browse the repository at this point in the history
  • Loading branch information
simeonschaub authored Aug 6, 2024
1 parent 308cd7b commit 09e5c40
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions base/strings/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ function join(io::IO, iterator, delim="")
end

function _join_preserve_annotations(iterator, args...)
if isconcretetype(eltype(iterator)) && !_isannotated(eltype(iterator)) && !any(_isannotated, args)
et = @default_eltype(iterator)
if isconcretetype(et) && !_isannotated(et) && !any(_isannotated, args)
sprint(join, iterator, args...)
else
io = AnnotatedIOBuffer()
Expand All @@ -363,7 +364,7 @@ function _join_preserve_annotations(iterator, args...)
# of iterators with a non-concrete eltype), that the result is annotated
# in nature, we extract an `AnnotatedString`, otherwise we just extract
# a plain `String` from `io`.
if isconcretetype(eltype(iterator)) || !isempty(io.annotations)
if isconcretetype(et) || !isempty(io.annotations)
read(seekstart(io), AnnotatedString{String})
else
String(take!(io.io))
Expand Down
5 changes: 5 additions & 0 deletions test/strings/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -344,3 +344,8 @@ end
@testset "`string` return types" begin
@test all(T -> T <: AbstractString, Base.return_types(string))
end

@testset "type stable `join` (#55389)" begin
itr = ("foo" for _ in 1:100)
@test Base.return_types(join, (typeof(itr),))[] == String
end

0 comments on commit 09e5c40

Please sign in to comment.