diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index bdf19ac7d013..582f27fe4036 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -1809,22 +1809,15 @@ object Parsers { NamedArg(name.toTypeName, argType()) } - def otherArgs(first: Tree, arg: () => Tree): List[Tree] = { - val rest = - if (in.token == COMMA) { - in.nextToken() - commaSeparated(arg) - } - else Nil - first :: rest - } if (namedOK && in.token == IDENTIFIER) - argType() match { - case Ident(name) if in.token == EQUALS => - in.nextToken() - otherArgs(NamedArg(name, argType()), () => namedTypeArg()) - case firstArg => - otherArgs(firstArg, () => argType()) + in.currentRegion.withCommasExpected { + argType() match { + case Ident(name) if in.token == EQUALS => + in.nextToken() + commaSeparatedRest(NamedArg(name, argType()), () => namedTypeArg()) + case firstArg => + commaSeparatedRest(firstArg, () => argType()) + } } else commaSeparated(() => argType()) } diff --git a/tests/pos/trailingCommas/trailingCommas.scala b/tests/pos/trailingCommas/trailingCommas.scala index 1e83edfab8f6..1ec185be78d2 100644 --- a/tests/pos/trailingCommas/trailingCommas.scala +++ b/tests/pos/trailingCommas/trailingCommas.scala @@ -85,6 +85,19 @@ trait FunTypeParamClause { A, B, ]: Unit + + def f1[ + A, + ]: Unit + + def g: Unit = f[ + Int, + String, + ] + + def g1: Unit = f1[ + Int, + ] } trait SimpleType {