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

disable string interpolation warning per-expr #9930

Closed
scabug opened this issue Sep 19, 2016 · 10 comments
Closed

disable string interpolation warning per-expr #9930

scabug opened this issue Sep 19, 2016 · 10 comments

Comments

@scabug
Copy link

scabug commented Sep 19, 2016

There's no way to tell the compiler, "No, I really do want a dollar sign in this string" without turning off the warning for the rest of the strings. This leads to weird hacks like string interpolating a string which you normally wouldn't have string interpolated in order to get rid of the warning.

@scabug
Copy link
Author

scabug commented Sep 19, 2016

Imported From: https://issues.scala-lang.org/browse/SI-9930?orig=1
Reporter: Moses Nakamura (mosesn)
Affected Versions: 2.11.8
See #8476

@scabug
Copy link
Author

scabug commented Sep 19, 2016

@SethTisue said:
duplicate of SI-8476?

@scabug
Copy link
Author

scabug commented Sep 19, 2016

Moses Nakamura (mosesn) said:
@seth: not sure. I wouldn't consider a feature flag that turns off this warning a fix, for example.

@scabug
Copy link
Author

scabug commented Sep 19, 2016

@som-snytt said:
IMHO, f"x$$y", which emits literal "x$y", is not weirder than any other syntax. It's nicer to have a specially-named interpolator that also refuses to do any interpolation, so you don't make a mistake the other way. I like the name lit"x$$y" for that. It would error on lit"x$$y$z" if z happened to be a value.

Another idea is an interpolator that does char replacement, a"x@y". Or a macro literally("x$y") that rewrites to f"x$$y".

Any sort of filter for reporting would require syntax. An annotation might work for syntax, but also require more work like the dotty reporting initiative.

@scabug
Copy link
Author

scabug commented Sep 19, 2016

Moses Nakamura (mosesn) said:
lit"x$$y$z" would work for me, as long as it didn't error if z happened to be a value.

@scabug
Copy link
Author

scabug commented Sep 20, 2016

@som-snytt said:
That's the same as s"x$$y$z".

@scabug
Copy link
Author

scabug commented Sep 20, 2016

Moses Nakamura (mosesn) said:
I'm not sure I understand. Doesn't s"x$$y$z" convert to "x$ywhateverisinz"? What I would want is for lit"x$$y$z" to convert to "x$$y$z".

@scabug
Copy link
Author

scabug commented Sep 20, 2016

@SethTisue said:
Moses: #8476 is about the same problem, so it seems better to me to have a single ticket for discussing possible solutions.

@scabug scabug closed this as completed Sep 20, 2016
@scabug
Copy link
Author

scabug commented Sep 20, 2016

@som-snytt said:
Just to clarify, any"$z" will error out if there is no value z; even if any is a macro, it doesn't get a chance to ignore the error and reparse the string to have arbitrary meaning, IIUC.

So, I suggested lit"x$$y" to mean "x$y" and in particular for the mistaken lit"x$$y$z" to error, because lit"x$$y$$z" was intended. It's just a way to cope with expressing constant strings with dollars, while still warning about "x$y".

I noticed that "interpolation" has the anagram "Operation: Lint".

@scabug
Copy link
Author

scabug commented Sep 20, 2016

Moses Nakamura (mosesn) said:
@seth: that's fair.
@ap: ugh, OK.

@scala scala deleted a comment from scabug Feb 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant