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

Only allow fansi.Str auto-construction for string literals #42

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

lihaoyi
Copy link
Member

@lihaoyi lihaoyi commented Dec 5, 2021

Having the implicit constructor apply to any CharSequence is dangerous, as often CharSequences have unknown contents and the construction of a fansi.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 a fansi.Str() constructor is tedious.

This PR makes it so that only string literals can be auto-converted to fansi.Strs, as we can be 99.99% sure string literals in the Scala source code do not contain weird escapes that might cause the fansi.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 the ErrorMode.

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

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

Successfully merging this pull request may close these issues.

2 participants