Skip to content

Commit 1ceaaa8

Browse files
DolphinChipstgodzik
authored andcommitted
Disallow empty parameter clauses in extension definition
[Cherry-picked 004579e]
1 parent ba8677c commit 1ceaaa8

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3412,7 +3412,10 @@ object Parsers {
34123412
// begin termParamClause
34133413
inParensWithCommas {
34143414
if in.token == RPAREN && paramOwner != ParamOwner.ExtensionPrefix && !impliedMods.is(Given)
3415-
then Nil
3415+
then
3416+
if paramOwner.takesOnlyUsingClauses then
3417+
syntaxError(em"`using` expected")
3418+
Nil
34163419
else
34173420
val clause =
34183421
if paramOwner == ParamOwner.ExtensionPrefix
@@ -4060,7 +4063,10 @@ object Parsers {
40604063
leadParamss += extParams
40614064
isUsingClause(extParams)
40624065
do ()
4063-
leadParamss ++= termParamClauses(ParamOwner.ExtensionFollow, numLeadParams)
4066+
// Empty parameter clauses are filtered out. They are already reported as syntax errors and are not
4067+
// allowed here.
4068+
val extFollowParams = termParamClauses(ParamOwner.ExtensionFollow, numLeadParams).filterNot(_.isEmpty)
4069+
leadParamss ++= extFollowParams
40644070
if in.isColon then
40654071
syntaxError(em"no `:` expected here")
40664072
in.nextToken()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
extension(x: Any)() // error
2+
def f = 42
3+
val x = Nil.f

0 commit comments

Comments
 (0)