Skip to content

Commit

Permalink
Dotty VarArg pattern (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
gosubpl committed Jun 2, 2017
1 parent cf12ba7 commit 7e2d1f9
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ def CiCommand(name: String)(commands: List[String]): Command =
case (state, command) => command :: state
}
}
def ci(command: String) = s"plz ${ciScalaVersion.get} $command"
def ci(command: String) = s"plz ${ciScalaVersion.getOrElse("No CI_SCALA_VERSION defined")} $command"

lazy val compilerOptions = Seq(
"-deprecation",
Expand Down
10 changes: 10 additions & 0 deletions readme/Rewrites.scalatex
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,16 @@
Such members already have a return type of @code{Unit} and sometimes this is unexpected.
Adding an explicit return type makes it more obvious.

@sect(DottyVarArgPattern.toString)
@p
Replaces @code{@@} symbols in VarArg patterns with a colon (@code{:}). See @lnk{http://dotty.epfl.ch/docs/reference/changed/vararg-patterns.html}

@hl.scala
// before
case List(1, 2, xs @@ _*)
// after
case List(1, 2, xs : _*)

@sect(NoAutoTupling.toString)
@p
Adds explicit tuples around argument lists where auto-tupling is occurring.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package scalafix.rewrite

import scala.meta._

import scala.meta.tokens.Token
import scalafix.Patch

case object DottyVarArgPattern extends Rewrite {
override def rewrite(ctx: RewriteCtx): Patch = {
val patches = ctx.tree.collect {
case bind @ Pat.Bind(_, Pat.Arg.SeqWildcard()) =>
ctx.tokenList.leading(bind.tokens.last).collectFirst {
case tok @ Token.At() =>
ctx.replaceToken(tok, ":")
}.asPatch
}
patches.asPatch
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ object ScalafixRewrites {
VolatileLazyVal,
RemoveXmlLiterals,
ExplicitUnit,
NoValInForComprehension
NoValInForComprehension,
DottyVarArgPattern
)
def semantic(mirror: Mirror): List[Rewrite] = List(
ExplicitReturnTypes(mirror),
Expand Down
12 changes: 12 additions & 0 deletions scalafix-tests/input/src/main/scala/test/DottyVarArgPattern.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
rewrites = DottyVarArgPattern
*/
package test

object DottyVarArgPattern {
List(1, 2, 3, 4) match {
case List(1, 2, xs @ _*) =>
}

val List(1, 2, x @ _*) = List(1, 2, 3, 4)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package test

object DottyVarArgPattern {
List(1, 2, 3, 4) match {
case List(1, 2, xs : _*) =>
}

val List(1, 2, x : _*) = List(1, 2, 3, 4)
}

0 comments on commit 7e2d1f9

Please sign in to comment.