Skip to content

Commit

Permalink
Relax and restrict only colon regions
Browse files Browse the repository at this point in the history
  • Loading branch information
som-snytt committed Feb 6, 2025
1 parent 1770f94 commit 4362c32
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/parsing/Scanners.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions tests/neg/i22527.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
)
12 changes: 5 additions & 7 deletions tests/pos/i22527.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ def f: Unit =
42
)

def g: Unit =
identity(
x =
class X extends AnyRef, Serializable
27
)

def test: Unit =
assert(
identity:
Expand All @@ -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

Expand Down

0 comments on commit 4362c32

Please sign in to comment.