Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AnnotatedString: wrong join() result with other string types #55198

Closed
aplavin opened this issue Jul 21, 2024 · 3 comments
Closed

AnnotatedString: wrong join() result with other string types #55198

aplavin opened this issue Jul 21, 2024 · 3 comments
Assignees

Comments

@aplavin
Copy link
Contributor

aplavin commented Jul 21, 2024

In both 1.11rc and nightly:

julia> using InlineStrings

julia> a = Base.AnnotatedString("annotated", [(1:9, :label => 1)])

julia> b = InlineString("abc")

# correct:
julia> a * b
"annotatedabc"

# wrong:
julia> join([a,b])
"annotated\x03cba"

# correct:
julia> join([String(a), b])
"annotatedabc"
@KristofferC
Copy link
Member

julia> using InlineStrings

julia> str = Base.AnnotatedString(InlineString("abc"))
"abc"

julia> sprint(print, str)
"\x03cba"

The problem is that AnnotatedStrings thinks that print and write are the same thing:

https://github.com/JuliaLang/StyledStrings.jl/blob/43fb018ed528d3b1b84c4bdb4ad682f20f0f7e7c/src/io.jl#L255-L256C6

tecosaur added a commit to JuliaLang/StyledStrings.jl that referenced this issue Jul 25, 2024
As raised in <JuliaLang/julia#55198>, once
we look at AbstractString types outside of Core/Base, their print
methods can be meaningfully different to write + returning nothing.

As such, instead of delegating printing to write, we need to call
_ansi_writer asking it to use the print function.
tecosaur added a commit to JuliaLang/StyledStrings.jl that referenced this issue Jul 25, 2024
As raised in <JuliaLang/julia#55198>, once
we look at AbstractString types outside of Core/Base, their print
methods can be meaningfully different to write + returning nothing.

As such, instead of delegating printing to write, we need to call
_ansi_writer asking it to use the print function.
@tecosaur
Copy link
Contributor

This is fixed in JuliaLang/StyledStrings.jl#66, I'll let tests run then merge + bump + backport.

tecosaur added a commit to JuliaLang/StyledStrings.jl that referenced this issue Jul 25, 2024
As raised in <JuliaLang/julia#55198>, once
we look at AbstractString types outside of Core/Base, their print
methods can be meaningfully different to write + returning nothing.

As such, instead of delegating printing to write, we need to call
_ansi_writer asking it to use the print function.
tecosaur added a commit to JuliaLang/StyledStrings.jl that referenced this issue Jul 25, 2024
As raised in <JuliaLang/julia#55198>, once
we look at AbstractString types outside of Core/Base, their print
methods can be meaningfully different to write + returning nothing.

As such, instead of delegating printing to write, we need to call
_ansi_writer asking it to use the print function.
tecosaur added a commit to JuliaLang/StyledStrings.jl that referenced this issue Jul 25, 2024
As raised in <JuliaLang/julia#55198>, once
we look at AbstractString types outside of Core/Base, their print
methods can be meaningfully different to write + returning nothing.

As such, instead of delegating printing to write, we need to call
_ansi_writer asking it to use the print function.
@tecosaur
Copy link
Contributor

#55461 updates the version of StyledStrings to include the fix.

@tecosaur tecosaur closed this as completed Sep 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants