From c64efd978219f7cd744283ed00c8376046ffe8e8 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sat, 16 Nov 2019 17:04:24 +0100 Subject: [PATCH] Fix #7516: Don't insert `` in front of `case` Don't insert outdent in front of CASE if indentation region belongs to a MATCH. --- compiler/src/dotty/tools/dotc/parsing/Scanners.scala | 9 +++++++-- tests/pos/i7516.scala | 3 +++ 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 tests/pos/i7516.scala diff --git a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala index 7b9f2e8565dd..45ca80004e05 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala @@ -555,9 +555,14 @@ object Scanners { token = INDENT end observeIndented - /** Insert an token if next token closes an indentation region */ + /** Insert an token if next token closes an indentation region. + * Exception: continue if indentation region belongs to a `match` and next token is `case`. + */ def observeOutdented(): Unit = currentRegion match - case r: Indented if !r.isOutermost && closingRegionTokens.contains(token) => + case r: Indented + if !r.isOutermost + && closingRegionTokens.contains(token) + && !(token == CASE && r.prefix == MATCH) => currentRegion = r.enclosing insert(OUTDENT, offset) case _ => diff --git a/tests/pos/i7516.scala b/tests/pos/i7516.scala new file mode 100644 index 000000000000..810474cd825b --- /dev/null +++ b/tests/pos/i7516.scala @@ -0,0 +1,3 @@ +val foo: Int => Int = Some(7) match + case Some(y) => x => y + case None => identity[Int]