From 983f414dd32752ff2dbca5a4637b0978b31d35a7 Mon Sep 17 00:00:00 2001 From: Dominik Gruntz Date: Fri, 13 Apr 2012 00:51:39 +0200 Subject: SI-5510: string interpolation: parser no longer hangs on unclosed string --- .../scala/tools/nsc/ast/parser/Scanners.scala | 10 ++++++++-- test/files/neg/t5510.check | 19 +++++++++++++++++++ test/files/neg/t5510.scala | 7 +++++++ 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 test/files/neg/t5510.check create mode 100644 test/files/neg/t5510.scala diff --git a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala index 81d81a4fb7..ce38f034cf 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala @@ -231,6 +231,12 @@ trait Scanners extends ScannersCommon { lastOffset -= 1 } if (inStringInterpolation) fetchStringPart() else fetchToken() + if(token == ERROR) { + if (inMultiLineInterpolation) + sepRegions = sepRegions.tail.tail + else if (inStringInterpolation) + sepRegions = sepRegions.tail + } } else { this copyFrom next next.token = EMPTY @@ -328,7 +334,7 @@ trait Scanners extends ScannersCommon { putChar(ch) nextChar() getIdentRest() - if (ch == '"' && token == IDENTIFIER && settings.Xexperimental.value) + if (ch == '"' && token == IDENTIFIER) token = INTERPOLATIONID case '<' => // is XMLSTART? val last = if (charOffset >= 2) buf(charOffset - 2) else ' ' @@ -697,7 +703,7 @@ trait Scanners extends ScannersCommon { do { putChar(ch) nextRawChar() - } while (Character.isUnicodeIdentifierPart(ch)) + } while (ch != SU && Character.isUnicodeIdentifierPart(ch)) next.token = IDENTIFIER next.name = newTermName(cbuf.toString) cbuf.clear() diff --git a/test/files/neg/t5510.check b/test/files/neg/t5510.check new file mode 100644 index 0000000000..f74e424dc4 --- /dev/null +++ b/test/files/neg/t5510.check @@ -0,0 +1,19 @@ +t5510.scala:2: error: unclosed string literal + val s1 = s"xxx + ^ +t5510.scala:3: error: unclosed string literal + val s2 = s"xxx $x + ^ +t5510.scala:4: error: unclosed string literal + val s3 = s"xxx $$ + ^ +t5510.scala:5: error: unclosed string literal + val s4 = ""s" + ^ +t5510.scala:6: error: unclosed multi-line string literal + val s5 = ""s""" $s1 $s2 s" + ^ +t5510.scala:7: error: Missing closing brace `}' assumed here +} + ^ +6 errors found diff --git a/test/files/neg/t5510.scala b/test/files/neg/t5510.scala new file mode 100644 index 0000000000..12630eb2cd --- /dev/null +++ b/test/files/neg/t5510.scala @@ -0,0 +1,7 @@ +object Test { + val s1 = s"xxx + val s2 = s"xxx $x + val s3 = s"xxx $$ + val s4 = ""s" + val s5 = ""s""" $s1 $s2 s" +} -- cgit v1.2.3