Skip to content

Commit 907f516

Browse files
authored
Merge pull request #6761 from dotty-staging/change-extmethod-nl
Allow a newline after the first parameter list of an extension method
2 parents 072f12a + bdc47d5 commit 907f516

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2537,7 +2537,7 @@ object Parsers {
25372537
/** DefDef ::= DefSig [(‘:’ | ‘<:’) Type] ‘=’ Expr
25382538
* | this ParamClause ParamClauses `=' ConstrExpr
25392539
* DefDcl ::= DefSig `:' Type
2540-
* DefSig ::= ‘(’ DefParam ‘)’ [nl] id [DefTypeParamClause] ParamClauses
2540+
* DefSig ::= [‘(’ DefParam ‘)’ [nl]] id [DefTypeParamClause] ParamClauses
25412541
*/
25422542
def defDefOrDcl(start: Offset, mods: Modifiers): Tree = atSpan(start, nameStart) {
25432543
def scala2ProcedureSyntax(resultTypeStr: String) = {
@@ -2567,7 +2567,8 @@ object Parsers {
25672567
} else {
25682568
val (leadingParamss, flags) =
25692569
if (in.token == LPAREN)
2570-
(paramClause(prefix = true) :: Nil, Method | Extension)
2570+
try (paramClause(prefix = true) :: Nil, Method | Extension)
2571+
finally newLineOpt()
25712572
else
25722573
(Nil, Method)
25732574
val mods1 = addFlag(mods, flags)

docs/docs/internals/syntax.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ Dcl ::= RefineDcl
357357
ValDcl ::= ids ‘:’ Type PatDef(_, ids, tpe, EmptyTree)
358358
VarDcl ::= ids ‘:’ Type PatDef(_, ids, tpe, EmptyTree)
359359
DefDcl ::= DefSig [‘:’ Type] DefDef(_, name, tparams, vparamss, tpe, EmptyTree)
360-
DefSig ::= ‘(’ DefParam ‘)’ [nl] id
360+
DefSig ::= [‘(’ DefParam ‘)’ [nl]] id
361361
[DefTypeParamClause] DefParamClauses
362362
TypeDcl ::= id [TypeParamClause] SubtypeBounds [‘=’ Type] TypeDefTree(_, name, tparams, bound
363363

tests/run/extension-methods.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ object Test extends App {
6161
}
6262

6363
class ListOrd[T: Ord] extends Ord[List[T]] {
64-
def (xs: List[T]) compareTo (ys: List[T]): Int = (xs, ys) match {
64+
def (xs: List[T])
65+
compareTo (ys: List[T]): Int = (xs, ys) match {
6566
case (Nil, Nil) => 0
6667
case (Nil, _) => -1
6768
case (_, Nil) => +1
@@ -87,8 +88,11 @@ object Test extends App {
8788
}
8889

8990
trait Monad[F[_]] extends Functor[F] {
90-
def (x: F[A]) flatMap [A, B](f: A => F[B]): F[B]
91-
def (x: F[A]) map [A, B](f: A => B) = x.flatMap(f `andThen` pure)
91+
def (x: F[A])
92+
flatMap [A, B](f: A => F[B]): F[B]
93+
94+
def (x: F[A])
95+
map [A, B](f: A => B) = x.flatMap(f `andThen` pure)
9296

9397
def pure[A](x: A): F[A]
9498
}

0 commit comments

Comments
 (0)