From f815f7a3d617e28445e285683b826c1dc29533bc Mon Sep 17 00:00:00 2001 From: TEC Date: Wed, 3 Apr 2024 21:02:52 +0800 Subject: [PATCH] Fix writing of AnnotatedChars to AnnotatedIOBuffer The AnnotatedString(::AnnotatedChar) constructor actually does not exist. Considering that String(::Char) is not defined, and we don't try this anywhere else, the obvious fix is to just construct the appropriate AnnotatedString here. We can think about more properly Char-optimised writes in the future if it comes up. --- base/strings/annotated.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/base/strings/annotated.jl b/base/strings/annotated.jl index a85cdf1b08bbb..28b68d64faff5 100644 --- a/base/strings/annotated.jl +++ b/base/strings/annotated.jl @@ -439,7 +439,8 @@ function write(io::AnnotatedIOBuffer, astr::Union{AnnotatedString, SubString{<:A write(io.io, String(astr)) end -write(io::AnnotatedIOBuffer, c::AnnotatedChar) = write(io, AnnotatedString(c)) +write(io::AnnotatedIOBuffer, c::AnnotatedChar) = + write(io, AnnotatedString(string(c), map(a -> (1:ncodeunits(c), a), annotations(c)))) write(io::AnnotatedIOBuffer, x::AbstractString) = write(io.io, x) write(io::AnnotatedIOBuffer, s::Union{SubString{String}, String}) = write(io.io, s) write(io::AnnotatedIOBuffer, b::UInt8) = write(io.io, b)