Skip to content

Disallow empty parameter clauses in extension definition #23143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3673,7 +3673,10 @@ object Parsers {
// begin termParamClause
inParensWithCommas {
if in.token == RPAREN && paramOwner != ParamOwner.ExtensionPrefix && !impliedMods.is(Given)
then Nil
then
if paramOwner.takesOnlyUsingClauses then
syntaxError(em"`using` expected")
Nil
else
val clause =
if paramOwner == ParamOwner.ExtensionPrefix
Expand Down Expand Up @@ -4468,7 +4471,10 @@ object Parsers {
leadParamss += extParams
isUsingClause(extParams)
do ()
leadParamss ++= termParamClauses(ParamOwner.ExtensionFollow, numLeadParams)
// Empty parameter clauses are filtered out. They are already reported as syntax errors and are not
// allowed here.
val extFollowParams = termParamClauses(ParamOwner.ExtensionFollow, numLeadParams).filterNot(_.isEmpty)
leadParamss ++= extFollowParams
if in.isColon then
syntaxError(em"no `:` expected here")
in.nextToken()
Expand Down
3 changes: 3 additions & 0 deletions tests/neg/extensions-can-only-have-using.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
extension(x: Any)() // error
def f = 42
val x = Nil.f
Loading