Skip to content

Commit

Permalink
Improve error position and recovery for bad dollar
Browse files Browse the repository at this point in the history
  • Loading branch information
som-snytt committed Jan 23, 2022
1 parent 047779a commit 6445e24
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/parsing/Scanners.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,9 @@ object Scanners {
finishNamedToken(IDENTIFIER, target = next)
}
else
error("invalid string interpolation: `$$`, `$\"`, `$`ident or `$`BlockExpr expected")
error("invalid string interpolation: `$$`, `$\"`, `$`ident or `$`BlockExpr expected", off = charOffset - 2)
putChar('$')
getStringPart(multiLine)
}
else {
val isUnclosedLiteral = !isUnicodeEscape && (ch == SU || (!multiLine && (ch == CR || ch == LF)))
Expand Down
4 changes: 4 additions & 0 deletions tests/neg/interpolator-dollar.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Error: tests/neg/interpolator-dollar.scala:5:20 ---------------------------------------------------------------------
5 | def oops = f"$s%s $<s" // error: invalid string interpolation
| ^
| invalid string interpolation: `$$`, `$"`, `$`ident or `$`BlockExpr expected
6 changes: 6 additions & 0 deletions tests/neg/interpolator-dollar.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

trait T {
def s = { println("SSS") ; "hello" }
def ok = String.format("%s, %<s", s)
def oops = f"$s%s $<s" // error: invalid string interpolation
}

0 comments on commit 6445e24

Please sign in to comment.