diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index f44703a562f1..d37ab3afc31c 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -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() @@ -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. diff --git a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala index ec246f7a3742..82c87152be96 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala @@ -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) diff --git a/tests/neg/i24496.scala b/tests/neg/i24496.scala new file mode 100644 index 000000000000..4d5ae7d7d6d5 --- /dev/null +++ b/tests/neg/i24496.scala @@ -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 diff --git a/tests/pos/i24496.scala b/tests/pos/i24496.scala new file mode 100644 index 000000000000..bdef831863a6 --- /dev/null +++ b/tests/pos/i24496.scala @@ -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