![JAR search and dependency download from the Maven repository](/logo.png)
io.getquill.util.InferImplicitValueWithFallback.scala Maven / Gradle / Ivy
package io.getquill.util
import scala.reflect.macros.whitebox.Context
object InferImplicitValueWithFallback {
def apply(c: Context)(tpe: c.Type, fallbackTree: c.Tree) = {
import c.universe._
def fallback =
c.typecheck(
q"""{
def infer = {
val t = $fallbackTree
import t._
_root_.scala.Predef.implicitly[$tpe]
}
infer
}""",
silent = true
)
c.inferImplicitValue(tpe).orElse(fallback) match {
case EmptyTree => None
case value => Some(value)
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy