Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,11 @@ object Parsers {
lookahead.skipParens()
isArrowIndent()
else if lookahead.token == CASE && in.featureEnabled(Feature.relaxedLambdaSyntax) then
Some(() => singleCaseMatch())
Some: () =>
inSepRegion(SingleLineLambda(_)):
singleCaseMatch()
.tap: _ =>
accept(ENDlambda)
else
None
isParamsAndArrow()
Expand Down Expand Up @@ -3228,6 +3232,9 @@ object Parsers {
val body = tok match
case ARROW => atSpan(in.skipToken()):
if exprOnly then
if in.token == ENDlambda then
in.token = NEWLINE
in.observeIndented()
if in.indentSyntax && in.isAfterLineEnd && in.token != INDENT then
warning(em"""Misleading indentation: this expression forms part of the preceding case.
|If this is intended, it should be indented for clarity.
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/parsing/Scanners.scala
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ object Scanners {
lastWidth = r.width
newlineIsSeparating = lastWidth <= nextWidth || r.isOutermost
indentPrefix = r.prefix
case _: InString => ()
case _: InString | _: SingleLineLambda => ()
case r =>
indentIsSignificant = indentSyntax
r.proposeKnownWidth(nextWidth, lastToken)
Expand Down
12 changes: 12 additions & 0 deletions tests/neg/i24496.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import scala.language.experimental.relaxedLambdaSyntax

@main def Test =
val list = List(1, 2, 3)

val three = list
.collect: case x =>
(x, x + 1)
.toMap // error value toMap is not a member of (Int, Int)

val huh = list
.collect: x => case y => (y, y + 1) // error expecting case at x
18 changes: 18 additions & 0 deletions tests/pos/i24496.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import scala.language.experimental.relaxedLambdaSyntax

@main def Test =
val list = List(1, 2, 3)

val three = list
.collect: case x =>
val y = x + 1
(x, y)
.toMap

val two = list
.collect: x => (x, x + 1)
.toMap

val one = list
.collect: case x => (x, x + 1)
.toMap
Loading