Skip to content

Commit

Permalink
Fix (return) type inference of Base.write
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tecosaur committed Feb 1, 2024
1 parent 60c956f commit a1b2ae2
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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)
Expand Down

0 comments on commit a1b2ae2

Please sign in to comment.