Skip to content

Do not discard amended format when f-interpolator warns #23697

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

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

Conversation

som-snytt
Copy link
Contributor

Also use the same error of kind Interpolation for warnings in s.

There are assorted errors that f emits, and a handful of warnings (about format string edge cases).

Previously, f would discard the amended "parts" and adapted "args" on any diagnostic; the transform would just call format directly, so the output looks normal. But the toString warning revealed that it loses the "injected" %s specifier; that would be witnessed only if one of the rare "edge case" warnings happened to be emitted. Now it does not discard on warnings, only on hard errors.

Fixes #23693

@som-snytt
Copy link
Contributor Author

som-snytt commented Aug 8, 2025

Note to self: it would have been easier to see what was going on if FormatInterpolatorTransform were inlined in StringInterpolatorOpt#transformF. It's confusing that Transform.checked dispatches to FormatChecker#checked. I see the components were confusing before the refactor or forward port, but it could be simpler; that is, extra layers harms local reasoning. It's also nice when names are different.

Edit: went ahead and inlined that code. The other suboptimal thing is "string is empty" means "error".

@som-snytt som-snytt marked this pull request as ready for review August 8, 2025 23:58
@Gedochao Gedochao requested a review from sjrd August 11, 2025 05:16
Copy link
Member

@sjrd sjrd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one comment on a comment, but otherwise LGTM

@@ -0,0 +1,19 @@
//> using options -Wtostring-interpolated

// verify warning messages and runtime result
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess "and runtime result" is inaccurate here, isn't it?

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.

String iterpolation warnings should have a error id
2 participants