Skip to content

Allow a newline after the first parameter list of an extension method #6761

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
Jun 29, 2019
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
5 changes: 3 additions & 2 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2537,7 +2537,7 @@ object Parsers {
/** DefDef ::= DefSig [(‘:’ | ‘<:’) Type] ‘=’ Expr
* | this ParamClause ParamClauses `=' ConstrExpr
* DefDcl ::= DefSig `:' Type
* DefSig ::= ‘(’ DefParam ‘)’ [nl] id [DefTypeParamClause] ParamClauses
* DefSig ::= [‘(’ DefParam ‘)’ [nl]] id [DefTypeParamClause] ParamClauses
*/
def defDefOrDcl(start: Offset, mods: Modifiers): Tree = atSpan(start, nameStart) {
def scala2ProcedureSyntax(resultTypeStr: String) = {
Expand Down Expand Up @@ -2567,7 +2567,8 @@ object Parsers {
} else {
val (leadingParamss, flags) =
if (in.token == LPAREN)
(paramClause(prefix = true) :: Nil, Method | Extension)
try (paramClause(prefix = true) :: Nil, Method | Extension)
finally newLineOpt()
else
(Nil, Method)
val mods1 = addFlag(mods, flags)
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/internals/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ Dcl ::= RefineDcl
ValDcl ::= ids ‘:’ Type PatDef(_, ids, tpe, EmptyTree)
VarDcl ::= ids ‘:’ Type PatDef(_, ids, tpe, EmptyTree)
DefDcl ::= DefSig [‘:’ Type] DefDef(_, name, tparams, vparamss, tpe, EmptyTree)
DefSig ::= ‘(’ DefParam ‘)’ [nl] id
DefSig ::= [‘(’ DefParam ‘)’ [nl]] id
[DefTypeParamClause] DefParamClauses
TypeDcl ::= id [TypeParamClause] SubtypeBounds [‘=’ Type] TypeDefTree(_, name, tparams, bound

Expand Down
10 changes: 7 additions & 3 deletions tests/run/extension-methods.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ object Test extends App {
}

class ListOrd[T: Ord] extends Ord[List[T]] {
def (xs: List[T]) compareTo (ys: List[T]): Int = (xs, ys) match {
def (xs: List[T])
compareTo (ys: List[T]): Int = (xs, ys) match {
case (Nil, Nil) => 0
case (Nil, _) => -1
case (_, Nil) => +1
Expand All @@ -87,8 +88,11 @@ object Test extends App {
}

trait Monad[F[_]] extends Functor[F] {
def (x: F[A]) flatMap [A, B](f: A => F[B]): F[B]
def (x: F[A]) map [A, B](f: A => B) = x.flatMap(f `andThen` pure)
def (x: F[A])
flatMap [A, B](f: A => F[B]): F[B]

def (x: F[A])
map [A, B](f: A => B) = x.flatMap(f `andThen` pure)

def pure[A](x: A): F[A]
}
Expand Down