Skip to content

Commit 456a6ab

Browse files
committed
No indent in named arg pattern
1 parent 595a86e commit 456a6ab

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -671,11 +671,14 @@ object Parsers {
671671
ts.toList
672672
else leading :: Nil
673673

674-
def maybeNamed(op: () => Tree): () => Tree = () =>
674+
def maybeNamed(location: Location, op: () => Tree): () => Tree = () =>
675675
if isIdent && in.lookahead.token == EQUALS && sourceVersion.enablesNamedTuples then
676676
atSpan(in.offset):
677677
val name = ident()
678678
in.nextToken()
679+
if location.inPattern && in.token == INDENT then
680+
in.currentRegion = in.currentRegion.outer
681+
in.nextToken()
679682
NamedArg(name, op())
680683
else op()
681684

@@ -2958,7 +2961,7 @@ object Parsers {
29582961
if isErased then isFormalParams = true
29592962
if isFormalParams then binding(Modifiers())
29602963
else
2961-
val t = maybeNamed(exprInParens)()
2964+
val t = maybeNamed(Location.InParens, exprInParens)()
29622965
if t.isInstanceOf[ValDef] then isFormalParams = true
29632966
t
29642967
commaSeparatedRest(exprOrBinding(), exprOrBinding)
@@ -3411,8 +3414,8 @@ object Parsers {
34113414
* | NamedPattern {‘,’ NamedPattern}
34123415
* NamedPattern ::= id '=' Pattern
34133416
*/
3414-
def patterns(location: Location = Location.InPattern): List[Tree] =
3415-
commaSeparated(maybeNamed(() => pattern(location)))
3417+
def patterns(location: Location = Location.InPattern): List[Tree] = // default used from Markup
3418+
commaSeparated(maybeNamed(location, () => pattern(location)))
34163419
// check that patterns are all named or all unnamed is done at desugaring
34173420

34183421
def patternsOpt(location: Location = Location.InPattern): List[Tree] =

tests/pos/i24474.scala

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
case class Foo(arg1: Int, arg2: Int)
2+
case class Bar(arg1: Int, arg2: Option[Int])
3+
4+
object OK:
5+
Foo(1, 2) match
6+
case Foo(arg1 =
7+
5
8+
) =>
9+
10+
object Test:
11+
Foo(1, 2) match
12+
case Foo(arg1 =
13+
5 // was: error: pattern expected
14+
) =>
15+
16+
object Nest:
17+
Bar(1, Option(2)) match
18+
case Bar(arg2 =
19+
Some(value =
20+
42
21+
)
22+
) =>
23+
24+
object Detupled:
25+
(fst = 1, snd = 2) match
26+
case (fst =
27+
5
28+
) =>

0 commit comments

Comments
 (0)