File tree 3 files changed +26
-3
lines changed
3 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -601,6 +601,20 @@ object Scanners {
601
601
lastWidth = r.knownWidth
602
602
newlineIsSeparating = r.isInstanceOf [InBraces ]
603
603
604
+ // can emit OUTDENT if line is not non-empty blank line at EOF
605
+ inline def isTrailingBlankLine : Boolean =
606
+ token == EOF && {
607
+ val end = buf.length - 1 // take terminal NL as empty last line
608
+ val prev = buf.lastIndexWhere(! isWhitespace(_), end = end)
609
+ prev < 0 || end - prev > 0 && isLineBreakChar(buf(prev))
610
+ }
611
+
612
+ inline def canDedent : Boolean =
613
+ lastToken != INDENT
614
+ && ! isLeadingInfixOperator(nextWidth)
615
+ && ! statCtdTokens.contains(lastToken)
616
+ && ! isTrailingBlankLine
617
+
604
618
if newlineIsSeparating
605
619
&& canEndStatTokens.contains(lastToken)
606
620
&& canStartStatTokens.contains(token)
@@ -613,9 +627,8 @@ object Scanners {
613
627
|| nextWidth == lastWidth && (indentPrefix == MATCH || indentPrefix == CATCH ) && token != CASE then
614
628
if currentRegion.isOutermost then
615
629
if nextWidth < lastWidth then currentRegion = topLevelRegion(nextWidth)
616
- else if ! isLeadingInfixOperator(nextWidth) && ! statCtdTokens.contains(lastToken) && lastToken != INDENT then
630
+ else if canDedent then
617
631
currentRegion match
618
- case _ if token == EOF => // no OUTDENT at EOF
619
632
case r : Indented =>
620
633
insert(OUTDENT , offset)
621
634
handleNewIndentWidth(r.enclosing, ir =>
Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ object Chars:
50
50
}
51
51
52
52
/** Is character a whitespace character (but not a new line)? */
53
- def isWhitespace (c : Char ): Boolean =
53
+ inline def isWhitespace (c : Char ): Boolean =
54
54
c == ' ' || c == '\t ' || c == CR
55
55
56
56
/** Can character form part of a doc comment variable $xxx? */
Original file line number Diff line number Diff line change @@ -400,6 +400,16 @@ class ReplCompilerTests extends ReplTest:
400
400
assertTrue(all.head.startsWith(" -- [E103] Syntax Error" ))
401
401
assertTrue(all.exists(_.trim().startsWith(" | Illegal start of statement: this modifier is not allowed here" )))
402
402
403
+ @ Test def `i22844 regression colon eol` : Unit = initially :
404
+ run :
405
+ """ |println:
406
+ | "hello, world"
407
+ |""" .stripMargin // outdent, but this test does not exercise the bug
408
+ assertEquals(List (" hello, world" ), lines())
409
+
410
+ @ Test def `i22844b regression colon arrow eol` : Unit = contextually :
411
+ assertTrue(ParseResult .isIncomplete(" List(42).map: x =>" ))
412
+
403
413
object ReplCompilerTests :
404
414
405
415
private val pattern = Pattern .compile(" \\ r[\\ n]?|\\ n" );
You can’t perform that action at this time.
0 commit comments