diff --git a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala index 4c902b0574e2..1cb9a29c6aef 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala @@ -470,16 +470,15 @@ object Scanners { else if indentIsSignificant then if nextWidth < lastWidth || nextWidth == lastWidth && (indentPrefix == MATCH || indentPrefix == CATCH) && token != CASE then - if !currentRegion.isOutermost && - !isLeadingInfixOperator() && - !statCtdTokens.contains(lastToken) then + if currentRegion.isOutermost then + if nextWidth < lastWidth then currentRegion = topLevelRegion(nextWidth) + else if !isLeadingInfixOperator() && !statCtdTokens.contains(lastToken) then currentRegion match case r: Indented => currentRegion = r.enclosing insert(OUTDENT, offset) case r: InBraces if !closingRegionTokens.contains(token) => - report.warning("Line is indented too far to the left, or a `}` is missing", - source.atSpan(Span(offset))) + report.warning("Line is indented too far to the left, or a `}` is missing", sourcePos()) case _ => else if lastWidth < nextWidth @@ -1316,7 +1315,7 @@ object Scanners { /* Initialization: read first char, then first token */ nextChar() nextToken() - currentRegion = Indented(indentWidth(offset), Set(), EMPTY, null) + currentRegion = topLevelRegion(indentWidth(offset)) } // end Scanner @@ -1357,6 +1356,8 @@ object Scanners { case class Indented(width: IndentWidth, others: Set[IndentWidth], prefix: Token, outer: Region | Null) extends Region: knownWidth = width + def topLevelRegion(width: IndentWidth) = Indented(width, Set(), EMPTY, null) + enum IndentWidth { case Run(ch: Char, n: Int) case Conc(l: IndentWidth, r: Run) diff --git a/tests/pos/i9992.scala b/tests/pos/i9992.scala new file mode 100644 index 000000000000..1a7a9e519645 --- /dev/null +++ b/tests/pos/i9992.scala @@ -0,0 +1,5 @@ + import scala.concurrent._ + +@main def test(): Unit = + def test = () + test diff --git a/tests/pos/opaques-queue.scala b/tests/pos/opaques-queue.scala new file mode 100644 index 000000000000..079ef7fde4f6 --- /dev/null +++ b/tests/pos/opaques-queue.scala @@ -0,0 +1,25 @@ +class Elem +trait QueueSignature: + type Queue + def empty: Queue + def append(q: Queue, e: Elem): Queue + def pop(q: Queue): Option[(Elem, Queue)] +val QueueModule: QueueSignature = + object QueueImpl extends QueueSignature: + type Queue = (List[Elem], List[Elem]) + def empty = (Nil, Nil) + def append(q: Queue, e: Elem): Queue = (q._1, e :: q._2) + def pop(q: Queue): Option[(Elem, Queue)] = q match + case (Nil, Nil) => None + case (x :: xs, ys) => Some((x, (xs, ys))) + case (Nil, ys) => pop((ys.reverse, Nil)) + QueueImpl + +object queues: + opaque type Queue = (List[Elem], List[Elem]) + def empty = (Nil, Nil) + def append(q: Queue, e: Elem): Queue = (q._1, e :: q._2) + def pop(q: Queue): Option[(Elem, Queue)] = q match + case (Nil, Nil) => None + case (x :: xs, ys) => Some((x, (xs, ys))) + case (Nil, ys) => pop((ys.reverse, Nil))