Skip to content

Commit 6445e24

Browse files
committed
Improve error position and recovery for bad dollar
1 parent 047779a commit 6445e24

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

compiler/src/dotty/tools/dotc/parsing/Scanners.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,9 @@ object Scanners {
11681168
finishNamedToken(IDENTIFIER, target = next)
11691169
}
11701170
else
1171-
error("invalid string interpolation: `$$`, `$\"`, `$`ident or `$`BlockExpr expected")
1171+
error("invalid string interpolation: `$$`, `$\"`, `$`ident or `$`BlockExpr expected", off = charOffset - 2)
1172+
putChar('$')
1173+
getStringPart(multiLine)
11721174
}
11731175
else {
11741176
val isUnclosedLiteral = !isUnicodeEscape && (ch == SU || (!multiLine && (ch == CR || ch == LF)))

tests/neg/interpolator-dollar.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Error: tests/neg/interpolator-dollar.scala:5:20 ---------------------------------------------------------------------
2+
5 | def oops = f"$s%s $<s" // error: invalid string interpolation
3+
| ^
4+
| invalid string interpolation: `$$`, `$"`, `$`ident or `$`BlockExpr expected

tests/neg/interpolator-dollar.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
trait T {
3+
def s = { println("SSS") ; "hello" }
4+
def ok = String.format("%s, %<s", s)
5+
def oops = f"$s%s $<s" // error: invalid string interpolation
6+
}

0 commit comments

Comments
 (0)