Skip to content

Commit f86cfb8

Browse files
committed
fix #55389: type-unstable join
1 parent 0717a94 commit f86cfb8

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

base/strings/io.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,8 @@ function join(io::IO, iterator, delim="")
354354
end
355355

356356
function _join_preserve_annotations(iterator, args...)
357-
if isconcretetype(eltype(iterator)) && !_isannotated(eltype(iterator)) && !any(_isannotated, args)
357+
et = @default_eltype(iterator)
358+
if isconcretetype(et) && !_isannotated(et) && !any(_isannotated, args)
358359
sprint(join, iterator, args...)
359360
else
360361
io = AnnotatedIOBuffer()
@@ -363,7 +364,7 @@ function _join_preserve_annotations(iterator, args...)
363364
# of iterators with a non-concrete eltype), that the result is annotated
364365
# in nature, we extract an `AnnotatedString`, otherwise we just extract
365366
# a plain `String` from `io`.
366-
if isconcretetype(eltype(iterator)) || !isempty(io.annotations)
367+
if isconcretetype(et) || !isempty(io.annotations)
367368
read(seekstart(io), AnnotatedString{String})
368369
else
369370
String(take!(io.io))

test/strings/io.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,3 +344,8 @@ end
344344
@testset "`string` return types" begin
345345
@test all(T -> T <: AbstractString, Base.return_types(string))
346346
end
347+
348+
@testset "type stable `join` (#55389)" begin
349+
itr = ("foo" for _ in 1:100)
350+
@test Base.return_types(join, (typeof(itr),))[] == String
351+
end

0 commit comments

Comments
 (0)