Can I create a Liftable for a parameterized trait in Scala 3 macros?

29 Views Asked by At
sealed trait Foo[T]
case class A() extends Foo[String]
case class B[V](v: V) extends Foo[Int]

given ToExpr[A] with {
  def apply(x: A)(using Quotes) =
    '{ A() }
}

given ToExpr[B] with {
  def apply(x: B[_])(using Quotes) =
    '{ B(x.v) }
}

inline def of[T]: RType[T] = ${ ofImpl[T]() }

def ofImpl[T]()(using quotes:Quotes)): Expr[Foo[T]] =
  import quotes.reflect.*
  Expr( B(15).asInstanceOf[RType[T]] ) // <<<---Doesn't work ;-)

I need my macro to return the generalized Foo[T], not the specific implementation.

Any way to do this?

0

There are 0 best solutions below