-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #238 from tofu-tf/ArgPassing
Pass target type as type argument for the macros
- Loading branch information
Showing
5 changed files
with
102 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package derevo | ||
package tests | ||
|
||
import scala.language.experimental.macros | ||
import scala.reflect.macros.blackbox | ||
|
||
trait Jampa[_] | ||
|
||
object JJ { | ||
type Of[U[_[_]]] = U[Jampa] | ||
} | ||
|
||
object Jampa extends DerivationKN3[JJ.Of] with PassTypeArgs { | ||
def instance[U[f[_]]]: U[Jampa] = macro jampa[U] | ||
|
||
def jampa[U[f[_]]](c: blackbox.Context)(implicit t: c.WeakTypeTag[U[Any]]): c.Tree = { | ||
import c.universe._ | ||
val u = t.tpe.typeConstructor.typeSymbol | ||
val jampa = typeOf[Jampa[Any]].typeConstructor | ||
q"new $u[$jampa]{}" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package derevo | ||
package tests | ||
|
||
import scala.languageFeature.experimental.macros | ||
import scala.reflect.ClassTag | ||
|
||
import org.scalatest.funsuite.AnyFunSuite | ||
|
||
@derive(Jampa) | ||
trait Goo[G[_]] { | ||
def goo = "goo" | ||
} | ||
|
||
class HigherKindedMacroSuite extends AnyFunSuite { | ||
test("goo should be goo") { | ||
assert(implicitly[Goo[Jampa]].goo === "goo") | ||
} | ||
} |