Skip to content

Commit 472d326

Browse files
committed
Tweak observeOutdented condition
Some OUTDENTs were not inserted because next token was not EMPTY. But the intent was that this should not be used for control flow. We now make the conditions when not to insert OUTDENT more explicit: don't insert OUTDENT in front of a `case` if the current region can accept `case`. # Conflicts: # compiler/src/dotty/tools/dotc/parsing/Scanners.scala
1 parent 1344826 commit 472d326

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

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

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -718,21 +718,18 @@ object Scanners {
718718

719719
/** Insert an <outdent> token if next token closes an indentation region.
720720
* or next token is a comma and we expect a comma in an outer region.
721-
* Exception: continue if indentation region belongs to a `match` or `catch1
722-
* and next token is `case`.
721+
* Exception: don't insert outdent in front of case if indentation region
722+
* accepts case
723723
*/
724724
def observeOutdented(): Unit = currentRegion match
725-
case r: Indented if !r.isOutermost =>
726-
if closingRegionTokens.contains(token)
727-
&& !(token == CASE && r.prefix == MATCH)
728-
&& next.token == EMPTY
729-
||
730-
token == COMMA
731-
&& r.outer.commasExpectedInEnclosing
732-
&& next.token == EMPTY
733-
then
734-
//if next.token != EMPTY then
735-
// println(i"NOT inserting outdent in front of $this, ${next.token}, ${r.prefix}")
725+
case r: Indented
726+
if !r.isOutermost
727+
&& (closingRegionTokens.contains(token)
728+
&& !(token == CASE && regionPrefixesAcceptingCase.contains(r.prefix))
729+
||
730+
token == COMMA && r.outer.commasExpectedInEnclosing)
731+
&& next.token == EMPTY
732+
=>
736733
insert(OUTDENT, offset)
737734
case _ =>
738735

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ object Tokens extends TokensCommon {
301301

302302
final val closingParens = BitSet(RPAREN, RBRACKET, RBRACE)
303303

304+
final val regionPrefixesAcceptingCase = BitSet(MATCH, CATCH, COLONeol)
305+
304306
final val softModifierNames = Set(nme.inline, nme.into, nme.opaque, nme.open, nme.transparent, nme.infix)
305307
// Note: update, consume and erased are missing here since they are only modifiers under some import
306308

0 commit comments

Comments
 (0)