Skip to content

Commit 8a3f8bc

Browse files
committed
Appease scalastyle
1 parent f9dfea0 commit 8a3f8bc

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

core/src/main/scala/cats/arrow/FunctionK.scala

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,19 @@ object FunctionKMacros extends MacroCompat {
4343
f: c.Expr[(F[α] G[α]) forSome { type α }]
4444
)(
4545
implicit evF: c.WeakTypeTag[F[_]], evG: c.WeakTypeTag[G[_]]
46-
): c.Expr[FunctionK[F, G]] = {
46+
): c.Expr[FunctionK[F, G]] =
47+
c.Expr[FunctionK[F, G]](new Lifter[c.type ](c).lift[F, G](f.tree))
48+
// ^^note: extra space after c.type to appease scalastyle
49+
50+
private[this] class Lifter[C <: Context](val c: C) {
4751
import c.universe._
4852

49-
def unblock(tree: Tree): Tree = tree match {
53+
private[this] def unblock(tree: Tree): Tree = tree match {
5054
case Block(Nil, expr) expr
5155
case _ tree
5256
}
5357

54-
def punchHole(tpe: Type): Tree = tpe match {
58+
private[this] def punchHole(tpe: Type): Tree = tpe match {
5559
case PolyType(undet :: Nil, underlying: TypeRef)
5660
val α = compatNewTypeName(c, "α")
5761
def rebind(typeRef: TypeRef): Tree =
@@ -71,29 +75,28 @@ object FunctionKMacros extends MacroCompat {
7175
c.abort(c.enclosingPosition, s"Unexpected type $tpe when lifting to FunctionK")
7276
}
7377

74-
val tree = unblock(f.tree) match {
75-
case q"""($param) => $trans[..$typeArgs](${ arg: Ident })""" if param.name == arg.name
76-
77-
typeArgs
78-
.collect { case tt: TypeTree => tt }
79-
.find(_.original != null)
80-
.foreach { param => c.abort(param.pos,
81-
s"type parameter $param must not be supplied when lifting function $trans to FunctionK")
78+
def lift[F[_], G[_]](tree: Tree)(implicit evF: c.WeakTypeTag[F[_]], evG: c.WeakTypeTag[G[_]]): Tree =
79+
unblock(tree) match {
80+
case q"""($param) => $trans[..$typeArgs](${ arg: Ident })""" if param.name == arg.name
81+
typeArgs
82+
.collect { case tt: TypeTree => tt }
83+
.find(tt => Option(tt.original).isDefined)
84+
.foreach { param => c.abort(param.pos,
85+
s"type parameter $param must not be supplied when lifting function $trans to FunctionK")
8286
}
8387

84-
val F = punchHole(evF.tpe)
85-
val G = punchHole(evG.tpe)
88+
val F = punchHole(evF.tpe)
89+
val G = punchHole(evG.tpe)
8690

87-
q"""
91+
q"""
8892
new FunctionK[$F, $G] {
8993
def apply[A](fa: $F[A]): $G[A] = $trans(fa)
9094
}
9195
"""
92-
case other
93-
c.abort(other.pos, s"Unexpected tree $other when lifting to FunctionK")
94-
}
96+
case other
97+
c.abort(other.pos, s"Unexpected tree $other when lifting to FunctionK")
98+
}
9599

96-
c.Expr[FunctionK[F, G]](tree)
97100
}
98101

99102
}

0 commit comments

Comments
 (0)