Skip to content

Commit 29d7b74

Browse files
committed
Fix annotated join with non-concrete eltype iters
As raised in <JuliaLang/StyledStrings.jl#57 (comment)>, when the eltype of an iterator is non-concrete, _isannotated can erroneously return false. To properly check such cases, we need to see if any of the elements of the iterator are annotated. This is a bit of an interesting case, since: - Most of the time it shouldn't be hit, we reasonably expect most iterables to infer as producing concrete types - The eltype of the iterator is (generally) known at compile-time, and so in any case other than the ambiguous non-concrete one, this check remains able to be done at compile-time. - Should the iterator be stateful and non-concrete, the check can consume some amount of the iterator before join is called. If it weren't for the edge-case of stateful iterators, I'd say this would be a fairly clean/straightforward fix, but since they exist I'm currently tempted to think the best compromise is just to avoid checking any Iterators.Stateful iterators. If somebody can work out a nicer compromise, that would be grand. Reported-by: kimikage <[email protected]>
1 parent 36a0da0 commit 29d7b74

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

base/strings/io.jl

+2-1
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 _isannotated(eltype(iterator)) || any(_isannotated, args)
357+
if _isannotated(eltype(iterator)) || any(_isannotated, args) ||
358+
(!isconcretetype(eltype(iterator)) && !isa(iterator, Iterators.Stateful) && any(_isannotated, iterator))
358359
io = AnnotatedIOBuffer()
359360
join(io, iterator, args...)
360361
read(seekstart(io), AnnotatedString{String})

0 commit comments

Comments
 (0)