Skip to content

Commit 3a2635d

Browse files
authored
Fix incorrect warning with -no-indent (#23216)
This PR change the condition to emit the warning “Line is indented too far to the right, or a `{` or `:` is missing” introduced in #7270 to only emit it if we are inside an `Indented` region. This fixes #21749.
2 parents 9d9e180 + 2072eba commit 3a2635d

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ object Parsers {
721721
def checkNextNotIndented(): Unit =
722722
if in.isNewLine then
723723
val nextIndentWidth = in.indentWidth(in.next.offset)
724-
if in.currentRegion.indentWidth < nextIndentWidth then
724+
if in.currentRegion.indentWidth < nextIndentWidth && in.currentRegion.closedBy == OUTDENT then
725725
warning(em"Line is indented too far to the right, or a `{` or `:` is missing", in.next.offset)
726726

727727
/* -------- REWRITES ----------------------------------------------------------- */

tests/pos/i21749.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//> using options -Xfatal-warnings -no-indent
2+
3+
object Test {
4+
1 match {
5+
case 1 =>
6+
case class Test(name: String)
7+
Nil
8+
}
9+
}

0 commit comments

Comments
 (0)