scala-macros

Implicit macro. Default implicit value. How?

我与影子孤独终老i 提交于 2020-12-15 07:07:08
问题 I don't even know how to ask the question. I have a macro that creates an instance of IsEnum[T] for a type T . I'm doing testing for it, and want to make sure that the implicit is not found for types that are not sealed, or that, in general, don't meet the requirements of an enum. So I created this method for testing def enumOf[T](implicit isEnum:IsEnum[T] = null) = isEnum And then I ensure that enumOf[NotAnEnum] == null But instead, it fails at compile time. One thing is the macro erroring.

Is there a type-class that checks for existence of at least one implicit of a type?

有些话、适合烂在心里 提交于 2020-12-05 11:48:25
问题 I have a trait Foo[T, U] and a type-level algorithm that given an L <: HList and a target type U , tells me whether there exists T in L such that there is an implicit Foo[T, U] in scope. This is implemented using the following type class: trait Search[L <: HList, U] object Search { def apply[L <: HList, U](implicit s: Search[L, U]): U = null ... } and we have the following: object Test { type L = Int :: String :: HNil implicit val foo: Foo[String, Boolean] = null Search[L, Boolean] //compiles