-
Notifications
You must be signed in to change notification settings - Fork 22
Closed as not planned
Labels
Description
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 barbut 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 elidedN.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
Reactions are currently unavailable