From 4362c327530ec7709f9e47f02b18f0986f61e657 Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Thu, 6 Feb 2025 09:41:27 -0800 Subject: [PATCH] Relax and restrict only colon regions --- .../src/dotty/tools/dotc/parsing/Scanners.scala | 4 ++-- tests/neg/i22527.scala | 13 +++++++------ tests/pos/i22527.scala | 12 +++++------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala index b2b2b6f57dea..952bddff6c7f 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala @@ -735,8 +735,8 @@ object Scanners { case _ => false currentRegion match case r: Indented if isEnclosedInParens(r.outer) => - // For some region prefixes (COLONeol, EQUALS) only OUTDENT if COMMA at EOL - if canStartIndentTokens.contains(r.prefix) && !statCtdTokens.contains(r.prefix) then + // For region prefix COLONeol, only OUTDENT if COMMA at EOL + if r.prefix == COLONeol then val lookahead = LookaheadScanner() lookahead.nextToken() if lookahead.isAfterLineEnd then diff --git a/tests/neg/i22527.scala b/tests/neg/i22527.scala index b9d9166e8fc2..4b80c21ff035 100644 --- a/tests/neg/i22527.scala +++ b/tests/neg/i22527.scala @@ -6,12 +6,6 @@ def test: Unit = true, "ok" // error end of statement expected but ',' found ) -def toss: Unit = - assert( - throw - null, "ok" // error same - ) - def callme[A](x: => A, msg: String) = try x.toString catch case t: RuntimeException => msg // not all indented regions require COMMA at EOL for OUTDENT @@ -22,3 +16,10 @@ def orElse(x: Int): Unit = true // error ',' or ')' expected, but 'true' found else false, "fail") + +def g: Unit = + identity( + x = + class X extends AnyRef, Serializable // error + 27 // error + ) diff --git a/tests/pos/i22527.scala b/tests/pos/i22527.scala index 055ed8acfae2..f02b22dc1205 100644 --- a/tests/pos/i22527.scala +++ b/tests/pos/i22527.scala @@ -6,13 +6,6 @@ def f: Unit = 42 ) -def g: Unit = - identity( - x = - class X extends AnyRef, Serializable - 27 - ) - def test: Unit = assert( identity: @@ -26,6 +19,11 @@ def toss: Unit = null, "ok" ) +def raise: Unit = + assert( + throw + null, "ok" // ok now + ) def callme[A](x: => A, msg: String) = try x.toString catch case t: RuntimeException => msg