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

Warn if interpolator uses toString #10776

Open
wants to merge 1 commit into
base: 2.13.x
Choose a base branch
from

Conversation

som-snytt
Copy link
Contributor

@som-snytt som-snytt commented May 7, 2024

Adds -Wtostring-interpolated which warns just for standard interpolators.

-Wconf:cat=w-flag-tostring-interpolated:e to boost.

Also restores edge case f"${ "hello" }%b" which is "true" for non-boolean arg. That became an error in previous refactor, possibly intentionally. (It is arguably an obscure feature of format.) (Edit: the C.I. error reminds me that the change was to make the expected type Boolean, so that conversions work normally. That is also edge casey. Maybe it can try boolean, null, and any? Edit: yes, try non-any first, then any if allowed.)

The "default" %s is improved so that the warning position is at the interpolated element in s"$x".

Follow-up to #8654

@scala-jenkins scala-jenkins added this to the 2.13.15 milestone May 7, 2024
@som-snytt som-snytt force-pushed the topic/warn-toString-interpolated branch 2 times, most recently from 6e463fb to ab4a1d1 Compare May 8, 2024 06:05
@som-snytt
Copy link
Contributor Author

Previous feedback at wartremover is to allow at least CharSequence and perhaps primitives with "canonical" representations (Int, Char, but not Float, Double). What about usual formatting of Int such as 1,024?

Therefore, no accommodation is made yet here.

A future version can take a typeclass, implicit locale, etc.

@som-snytt som-snytt marked this pull request as ready for review May 8, 2024 16:59
@som-snytt som-snytt force-pushed the topic/warn-toString-interpolated branch from ab4a1d1 to cbf369d Compare May 8, 2024 17:13
@SethTisue SethTisue added the release-notes worth highlighting in next release notes label May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-notes worth highlighting in next release notes
Projects
None yet
3 participants