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

False positive in missing interpolator warning #10217

Closed
scabug opened this issue Mar 2, 2017 · 6 comments
Closed

False positive in missing interpolator warning #10217

scabug opened this issue Mar 2, 2017 · 6 comments

Comments

@scabug
Copy link

scabug commented Mar 2, 2017

scala> object T; """foo \$T bar"""
<console>:13: warning: possible missing interpolator: detected interpolated identifier `$T`
 """foo \$T bar"""
 ^
defined object T
res0: String = foo \$T bar

but then..

scala> object T; s"""foo \$T bar"""
scala.StringContext$InvalidEscapeException: invalid escape at terminal index 4 in "foo \". Use \\ for literal \.
  at scala.StringContext$.loop$1(StringContext.scala:211)
  at scala.StringContext$.replace$1(StringContext.scala:246)
  at scala.StringContext$.treatEscapes0(StringContext.scala:250)
  at scala.StringContext$.treatEscapes(StringContext.scala:195)
  at scala.StringContext.$anonfun$s$1(StringContext.scala:95)
  at scala.StringContext.standardInterpolator(StringContext.scala:123)
  at scala.StringContext.s(StringContext.scala:95)
  ... 29 elided

N.B. the difference between line 1 and line 2 is the extra 's' before the string.

The compiler warns about a "possible missing interpolator" when no interpolation would occur.

workaround

Use the f-interpolator and double the "$"'s and the ""s:

scala> object T; f"""foo \\$$T bar"""
object T
val res2: String = foo \$T bar
@scabug
Copy link
Author

scabug commented Mar 2, 2017

Imported From: https://issues.scala-lang.org/browse/SI-10217?orig=1
Reporter: @dwijnand
Affected Versions: 2.12.1
See #6476, #8761

@scabug
Copy link
Author

scabug commented Mar 2, 2017

@dwijnand said:
The arch-enemy of #8761.

@scabug
Copy link
Author

scabug commented Mar 2, 2017

@som-snytt said:
Suggest renaming it -Xlint:possible-missing-interpolator.

#6476 means """\$""" does not unambiguously express escaped dollar.

For example, file"""C:\Program Files\$name""".

The linter could be improved to check only possible interpolators. -Xlint:possible-missing-possible-interpolator

If the interpolator is a macro, it could check for success before warning; but failure (like a bad escape) could mean I haven't worked out the confusing syntax yet.

I asked about the linked issue on gitter recently and nobody cared. As with shoes, one cares only if they pinch, or if they're really great shoes.

@scabug
Copy link
Author

scabug commented Mar 2, 2017

@dwijnand said:
I wouldn't infer anything from a forum such as a Gitter room.

In accordance to your new year's resolution: Do you think this is a bug or not?

@scabug
Copy link
Author

scabug commented Mar 2, 2017

@som-snytt said:
I think it's an improvement if the message were to indicate which available interpolators succeed or fail (if macros), otherwise assume failure.

@som-snytt
Copy link

The last suggestion was to suggest:

did you mean `raw"\$T"`?

That would be clever mind reading.

Closing as not a bug because of the example for windows file names.

Alternatively, use a hypothetical id"\$T" which does nothing but reconstruct the literal text.

As of 2.13, there is no warning for seeming to interpolate a module (object); and \ is escape for quote in strings and interpolations.

@som-snytt som-snytt closed this as not planned Won't fix, can't repro, duplicate, stale Feb 21, 2024
@SethTisue SethTisue removed this from the Backlog milestone Feb 21, 2024
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

3 participants