Only allow fansi.Str auto-construction for string literals #42
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Having the implicit constructor apply to any
CharSequence
is dangerous, as oftenCharSequence
s have unknown contents and the construction of afansi.Str
might fail (configurable to mean throw, strip, or sanitize) if it contains weird escapes. On the other hand, having to wrap every string literal in afansi.Str()
constructor is tedious.This PR makes it so that only string literals can be auto-converted to
fansi.Str
s, as we can be 99.99% sure string literals in the Scala source code do not contain weird escapes that might cause thefansi.Str
constructor to fail. For string variables which do not have known contents, we force the user to wrap them explicitly, to ensure the points at which we are doing a potentially-unsafe conversion are explicit and the user has a chance to specify theErrorMode
.This is a breaking change, so since we're already breaking compat in a few places in com-lihaoyi we should include this in the update.
The new constraint doesn't work in Scala3 for some reason scala/scala3#14040
Review by @lolgab