Skip to content

Instantly share code, notes, and snippets.

@jatcwang
Created November 2, 2024 11:19
Show Gist options
  • Save jatcwang/c975907fb471e0f704823cdcaad03795 to your computer and use it in GitHub Desktop.
Save jatcwang/c975907fb471e0f704823cdcaad03795 to your computer and use it in GitHub Desktop.
Scala 3 macro to print resolved implicit / given tree
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