From a1b2ae2434cd7d8199fa8647339422fe0e1d0324 Mon Sep 17 00:00:00 2001 From: TEC Date: Thu, 1 Feb 2024 20:50:33 +0800 Subject: [PATCH] Fix (return) type inference of Base.write Just the "where {F <: Function}" change should be enough to correct type inference in theory, but Base.return_type still gave "Any" with just that change, so we're also adding a type assertion to the write method. --- src/io.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/io.jl b/src/io.jl index 96ee2aeb..c15cce3c 100644 --- a/src/io.jl +++ b/src/io.jl @@ -216,7 +216,7 @@ function termstyle(io::IO, face::Face, lastface::Face=getface()) end function _ansi_writer(io::IO, s::Union{<:AnnotatedString, SubString{<:AnnotatedString}}, - string_writer::Function) + string_writer::F) where {F <: Function} if get(io, :color, false)::Bool buf = IOBuffer() # Avoid the overhead in repeatadly printing to `stdout` lastface::Face = FACES.default[:default] @@ -243,7 +243,7 @@ function _ansi_writer(io::IO, s::Union{<:AnnotatedString, SubString{<:AnnotatedS end write(io::IO, s::Union{<:AnnotatedString, SubString{<:AnnotatedString}}) = - _ansi_writer(io, s, write) + _ansi_writer(io, s, write)::Int print(io::IO, s::Union{<:AnnotatedString, SubString{<:AnnotatedString}}) = (write(io, s); nothing)