Skip to content

Commit 267a7e4

Browse files
authored
Merge pull request #15395 from albertpchen/fix-type-arg-trailing-comma-parse-error
Fix parser error for type arguments with trailing comma
2 parents c6de910 + 9905698 commit 267a7e4

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

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

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,22 +1809,15 @@ object Parsers {
18091809
NamedArg(name.toTypeName, argType())
18101810
}
18111811

1812-
def otherArgs(first: Tree, arg: () => Tree): List[Tree] = {
1813-
val rest =
1814-
if (in.token == COMMA) {
1815-
in.nextToken()
1816-
commaSeparated(arg)
1817-
}
1818-
else Nil
1819-
first :: rest
1820-
}
18211812
if (namedOK && in.token == IDENTIFIER)
1822-
argType() match {
1823-
case Ident(name) if in.token == EQUALS =>
1824-
in.nextToken()
1825-
otherArgs(NamedArg(name, argType()), () => namedTypeArg())
1826-
case firstArg =>
1827-
otherArgs(firstArg, () => argType())
1813+
in.currentRegion.withCommasExpected {
1814+
argType() match {
1815+
case Ident(name) if in.token == EQUALS =>
1816+
in.nextToken()
1817+
commaSeparatedRest(NamedArg(name, argType()), () => namedTypeArg())
1818+
case firstArg =>
1819+
commaSeparatedRest(firstArg, () => argType())
1820+
}
18281821
}
18291822
else commaSeparated(() => argType())
18301823
}

tests/pos/trailingCommas/trailingCommas.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,19 @@ trait FunTypeParamClause {
8585
A,
8686
B,
8787
]: Unit
88+
89+
def f1[
90+
A,
91+
]: Unit
92+
93+
def g: Unit = f[
94+
Int,
95+
String,
96+
]
97+
98+
def g1: Unit = f1[
99+
Int,
100+
]
88101
}
89102

90103
trait SimpleType {

0 commit comments

Comments
 (0)