From d166d2cb6da06ab908ceb2a8e283df749f3a5e8e Mon Sep 17 00:00:00 2001 From: Timothy Date: Thu, 18 Apr 2024 23:59:44 +0800 Subject: [PATCH] Fix writing of AnnotatedChars to AnnotatedIOBuffer (#53941) 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. (cherry picked from commit 42b3134d9cb0351070d67183eb479b67d22f2c66) --- 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 28aa092c578bd..2a331c5133f83 100644 --- a/base/strings/annotated.jl +++ b/base/strings/annotated.jl @@ -484,7 +484,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)