Skip to content

Commit bbb1c60

Browse files
committed
Single line case lambda gets a region
1 parent 91351e3 commit bbb1c60

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,11 @@ object Parsers {
11371137
lookahead.skipParens()
11381138
isArrowIndent()
11391139
else if lookahead.token == CASE && in.featureEnabled(Feature.relaxedLambdaSyntax) then
1140-
Some(() => singleCaseMatch())
1140+
Some: () =>
1141+
inSepRegion(SingleLineLambda(_)):
1142+
singleCaseMatch()
1143+
.tap: _ =>
1144+
accept(ENDlambda)
11411145
else
11421146
None
11431147
isParamsAndArrow()

tests/neg/i24496.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import scala.language.experimental.relaxedLambdaSyntax
2+
3+
@main def Test =
4+
val list = List(1, 2, 3)
5+
6+
val three = list
7+
.collect: case x =>
8+
(x, x + 1) // error not a member of tuple
9+
.toMap
10+
11+
val huh = list
12+
.collect: x => case y => (y, y + 1) // error expecting case at x

tests/pos/i24496.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import scala.language.experimental.relaxedLambdaSyntax
2+
3+
@main def Test =
4+
val list = List(1, 2, 3)
5+
6+
val two = list
7+
.collect: x => (x, x + 1)
8+
.toMap
9+
10+
val one = list
11+
.collect: case x => (x, x + 1)
12+
.toMap
13+
14+
//val huh = list
15+
// .collect: x => case y => (y, y + 1) correctly errors expecting case at x

0 commit comments

Comments
 (0)