Skip to content

Commit

Permalink
KindProjectorScala3TypeLambda
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwei-k committed Jan 12, 2025
1 parent a958797 commit 9ddccf1
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
2 changes: 2 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ lazy val inputOutputCommon = Def.settings(
scalaBinaryVersion.value match {
case "2.13" =>
Seq("-Wconf:cat=scala3-migration:info")
case "3" =>
Seq("-Ykind-projector")
case _ =>
Nil
}
Expand Down
10 changes: 10 additions & 0 deletions input/src/main/scala-3/fix/KindProjectorScala3TypeLambdaTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
rule = KindProjectorScala3TypeLambda
*/
package fix

trait KindProjectorScala3TypeLambdaTest {
type X1[b] = λ[a => Either[a, b]]

def f: X1[Int][String] = Right(2).withLeft[String]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package fix

trait KindProjectorScala3TypeLambdaTest {
type X1[b] = [a] =>> Either[a, b]

def f: X1[Int][String] = Right(2).withLeft[String]
}
25 changes: 25 additions & 0 deletions rules/src/main/scala/fix/KindProjectorScala3TypeLambda.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package fix

import scala.meta.Type
import scala.meta.XtensionCollectionLikeUI
import scalafix.Patch
import scalafix.v1.SyntacticDocument
import scalafix.v1.SyntacticRule
import scalafix.v1.XtensionSeqPatch

class KindProjectorScala3TypeLambda extends SyntacticRule("KindProjectorScala3TypeLambda") {
override def fix(implicit doc: SyntacticDocument): Patch = {
doc.tree.collect {
case t @ Type.Apply.After_4_6_0(
Type.Name("λ"),
Type.ArgClause(
Type.Function.After_4_6_0(
Type.FuncParamClause(args),
body
) :: Nil
)
) =>
Patch.replaceTree(t, args.mkString("[", ", ", s"] =>> ${body}"))
}.asPatch
}
}

0 comments on commit 9ddccf1

Please sign in to comment.