Created
November 2, 2024 11:19
-
-
Save jatcwang/c975907fb471e0f704823cdcaad03795 to your computer and use it in GitHub Desktop.
Scala 3 macro to print resolved implicit / given tree
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
import scala.quoted.* | |
inline def printResolvedImplicit[A]: Unit = | |
${ printResolvedImplicitImpl[A] } | |
private def printResolvedImplicitImpl[A](using quotes: Quotes, t: Type[A]): Expr[Unit] = | |
import quotes.reflect.* | |
Expr.summon[A].match { | |
case Some(ex) => println(ex.asTerm.show(using Printer.TreeCode)) | |
case None => report.error("Implicit resolution failed") | |
} | |
'{ () } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment