Skip to content

Commit 4cc2f41

Browse files
committed
1 parent 338454a commit 4cc2f41

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/strings/io.jl

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

33
function _join_preserve_annotations(iterator, args...)
4-
if _isannotated(eltype(iterator)) || any(_isannotated, args)
4+
if isconcretetype(eltype(iterator)) && !_isannotated(eltype(iterator)) && !any(_isannotated, args)
5+
sprint(join, iterator, args...)
6+
else
57
io = AnnotatedIOBuffer()
68
join(io, iterator, args...)
7-
read(seekstart(io), AnnotatedString{String})
8-
else
9-
sprint(join, iterator, args...)
9+
# If we know (from compile time information, or dynamically in the case
10+
# of iterators with a non-concrete eltype), that the result is annotated
11+
# in nature, we extract an `AnnotatedString`, otherwise we just extract
12+
# a plain `String` from `io`.
13+
if isconcretetype(eltype(iterator)) || !isempty(io.annotations)
14+
read(seekstart(io), AnnotatedString{String})
15+
else
16+
String(take!(io.io))
17+
end
1018
end
1119
end
1220

0 commit comments

Comments
 (0)