File tree Expand file tree Collapse file tree 4 files changed +23
-15
lines changed
compiler/src/dotty/tools/dotc/parsing Expand file tree Collapse file tree 4 files changed +23
-15
lines changed Original file line number Diff line number Diff line change @@ -3230,15 +3230,20 @@ object Parsers {
32303230 atSpan(self.span)(Block (Nil , EmptyTree ))
32313231
32323232 val body = tok match
3233- case ARROW => atSpan(in.skipToken()):
3234- if exprOnly then
3235- if in.indentSyntax && in.isAfterLineEnd && in.token != INDENT then
3236- warning(em """ Misleading indentation: this expression forms part of the preceding case.
3237- |If this is intended, it should be indented for clarity.
3238- |Otherwise, if the handler is intended to be empty, use a multi-line match or catch with
3239- |an indented case. """ )
3240- expr()
3241- else block()
3233+ case ARROW =>
3234+ val arrowAt = in.offset
3235+ atSpan(in.skipToken()):
3236+ if exprOnly then
3237+ if in.token == ENDlambda && source.offsetToLine(arrowAt) != source.offsetToLine(in.offset) then
3238+ in.token = NEWLINE
3239+ in.observeIndented()
3240+ if in.indentSyntax && in.isAfterLineEnd && in.token != INDENT then
3241+ warning(em """ Misleading indentation: this expression forms part of the preceding case.
3242+ |If this is intended, it should be indented for clarity.
3243+ |Otherwise, if the handler is intended to be empty, use a multi-line match or catch with
3244+ |an indented case. """ )
3245+ expr()
3246+ else block()
32423247 case IF => atSpan(in.skipToken()):
32433248 // a sub match after a guard is parsed the same as one without
32443249 val t = inSepRegion(InCase )(postfixExpr(Location .InGuard ))
Original file line number Diff line number Diff line change @@ -596,7 +596,7 @@ object Scanners {
596596 lastWidth = r.width
597597 newlineIsSeparating = lastWidth <= nextWidth || r.isOutermost
598598 indentPrefix = r.prefix
599- case _ : InString => ()
599+ case _ : InString | _ : SingleLineLambda => ()
600600 case r =>
601601 indentIsSignificant = indentSyntax
602602 r.proposeKnownWidth(nextWidth, lastToken)
Original file line number Diff line number Diff line change @@ -5,8 +5,8 @@ import scala.language.experimental.relaxedLambdaSyntax
55
66 val three = list
77 .collect: case x =>
8- (x, x + 1 ) // error not a member of tuple
9- .toMap
8+ (x, x + 1 )
9+ .toMap // error value toMap is not a member of (Int, Int)
1010
1111 val huh = list
1212 .collect: x => case y => (y, y + 1 ) // error expecting case at x
Original file line number Diff line number Diff line change @@ -3,13 +3,16 @@ import scala.language.experimental.relaxedLambdaSyntax
33@ main def Test =
44 val list = List (1 , 2 , 3 )
55
6+ val three = list
7+ .collect: case x =>
8+ val y = x + 1
9+ (x, y)
10+ .toMap
11+
612 val two = list
713 .collect: x => (x, x + 1 )
814 .toMap
915
1016 val one = list
1117 .collect: case x => (x, x + 1 )
1218 .toMap
13-
14- // val huh = list
15- // .collect: x => case y => (y, y + 1) correctly errors expecting case at x
You can’t perform that action at this time.
0 commit comments