Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 004579e

Browse files
DolphinChipssom-snytt
authored andcommitted
Disallow empty parameter clauses in extension definition
1 parent e5a9355 commit 004579e

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
@@ -3673,7 +3673,10 @@ object Parsers {
36733673
// begin termParamClause
36743674
inParensWithCommas {
36753675
if in.token == RPAREN && paramOwner != ParamOwner.ExtensionPrefix && !impliedMods.is(Given)
3676-
then Nil
3676+
then
3677+
if paramOwner.takesOnlyUsingClauses then
3678+
syntaxError(em"`using` expected")
3679+
Nil
36773680
else
36783681
val clause =
36793682
if paramOwner == ParamOwner.ExtensionPrefix
@@ -4468,7 +4471,10 @@ object Parsers {
44684471
leadParamss += extParams
44694472
isUsingClause(extParams)
44704473
do ()
4471-
leadParamss ++= termParamClauses(ParamOwner.ExtensionFollow, numLeadParams)
4474+
// Empty parameter clauses are filtered out. They are already reported as syntax errors and are not
4475+
// allowed here.
4476+
val extFollowParams = termParamClauses(ParamOwner.ExtensionFollow, numLeadParams).filterNot(_.isEmpty)
4477+
leadParamss ++= extFollowParams
44724478
if in.isColon then
44734479
syntaxError(em"no `:` expected here")
44744480
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)

AltStyle によって変換されたページ (->オリジナル) /