summaryrefslogtreecommitdiff
path: root/src/library/scala/StringContext.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/library/scala/StringContext.scala')
-rw-r--r--src/library/scala/StringContext.scala11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/library/scala/StringContext.scala b/src/library/scala/StringContext.scala
index ed3b305d59..2632994a34 100644
--- a/src/library/scala/StringContext.scala
+++ b/src/library/scala/StringContext.scala
@@ -163,7 +163,7 @@ case class StringContext(parts: String*) {
*/
// The implementation is hardwired to `scala.tools.reflect.MacroImplementations.macro_StringInterpolation_f`
// Using the mechanism implemented in `scala.tools.reflect.FastTrack`
- def f(args: Any*): String = macro ???
+ def f[A >: Any](args: A*): String = macro ???
}
object StringContext {
@@ -173,8 +173,13 @@ object StringContext {
* @param str The offending string
* @param idx The index of the offending backslash character in `str`.
*/
- class InvalidEscapeException(str: String, @deprecatedName('idx) val index: Int)
- extends IllegalArgumentException("invalid escape character at index "+index+" in \""+str+"\"")
+ class InvalidEscapeException(str: String, @deprecatedName('idx) val index: Int) extends IllegalArgumentException(
+ s"""invalid escape ${
+ require(index >= 0 && index < str.length)
+ val ok = """[\b, \t, \n, \f, \r, \\, \", \']"""
+ if (index == str.length - 1) "at terminal" else s"'\\${str(index + 1)}' not one of $ok at"
+ } index $index in "$str". Use \\\\ for literal \\."""
+ )
/** Expands standard Scala escape sequences in a string.
* Escape sequences are: