All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.getquill.util.InferImplicitValueWithFallback.scala Maven / Gradle / Ivy

There is a newer version: 4.6.0
Show newest version
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