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]