File tree Expand file tree Collapse file tree 4 files changed +21
-8
lines changed
src/compiler/scala/tools/nsc/ast/parser Expand file tree Collapse file tree 4 files changed +21
-8
lines changed Original file line number Diff line number Diff line change @@ -532,6 +532,15 @@ trait Scanners extends ScannersCommon {
532
532
}
533
533
fetchDoubleQuote()
534
534
case '\' ' =>
535
+ def unclosedCharLit () = {
536
+ val msg = " unclosed character literal"
537
+ // previous token was Symbol contiguous with the orphan single quote at offset
538
+ if (token == SYMBOLLIT && offset == lastOffset) {
539
+ syntaxError(s """ $msg (or use " for string literal " $strVal") """ )
540
+ } else {
541
+ syntaxError(msg)
542
+ }
543
+ }
535
544
def fetchSingleQuote () = {
536
545
nextChar()
537
546
if (isIdentifierStart(ch))
@@ -545,16 +554,14 @@ trait Scanners extends ScannersCommon {
545
554
}
546
555
else if (! isAtEnd && (ch != SU && ch != CR && ch != LF || isUnicodeEscape)) {
547
556
getLitChar()
548
- if (ch == '\' ' ) {
557
+ if (ch != '\' ' ) unclosedCharLit()
558
+ else {
549
559
nextChar()
550
560
token = CHARLIT
551
561
setStrVal()
552
- } else {
553
- syntaxError(" unclosed character literal" )
554
562
}
555
563
}
556
- else
557
- syntaxError(" unclosed character literal" )
564
+ else unclosedCharLit()
558
565
}
559
566
fetchSingleQuote()
560
567
case '.' =>
@@ -786,7 +793,7 @@ trait Scanners extends ScannersCommon {
786
793
next.token = kwArray(idx)
787
794
}
788
795
} else {
789
- syntaxError(" invalid string interpolation: `$$', `$'ident or `$'BlockExpr expected " )
796
+ syntaxError(s " invalid string interpolation $$ $ch , expected: $$$$ , $$ identifier or $$ {expression} " )
790
797
}
791
798
} else {
792
799
val isUnclosedLiteral = ! isUnicodeEscape && (ch == SU || (! multiLine && (ch == CR || ch == LF )))
Original file line number Diff line number Diff line change @@ -7,4 +7,7 @@ badtok-1.scala:2: error: unclosed character literal
7
7
badtok-1.scala:6: error: empty character literal (use '\'' for single quote)
8
8
'''
9
9
^
10
- three errors found
10
+ badtok-1.scala:9: error: unclosed character literal (or use " for string literal "abc")
11
+ 'abc'
12
+ ^
13
+ four errors found
Original file line number Diff line number Diff line change 4
4
5
5
// SI-10133
6
6
'''
7
+
8
+ // SI-10120
9
+ 'abc '
Original file line number Diff line number Diff line change 1
- t5856.scala:10: error: invalid string interpolation: `$$', `$'ident or `$'BlockExpr expected
1
+ t5856.scala:10: error: invalid string interpolation $", expected: $$, $identifier or ${expression}
2
2
val s9 = s"$"
3
3
^
4
4
t5856.scala:10: error: unclosed string literal
You can’t perform that action at this time.
0 commit comments