Calling `super` in a Scala 3 macro

  1. Hello, I am trying to implement a Scala 3 macro that overrides a method. I am struggling with calling the super . My currently working attempt has to explicitly specify the result type of the method:
Super(This(cls), None).select(method).asExprOf[String]

I’d like to implement this in a generic way, something like:

Super(This(cls), None).select(method).asExprOf(using method.tree.asInstanceOf[DefDef].returnTpt.tpe.asType)

But I am getting, logically, the following error:

[error]    |                        Found:    scala.quoted.Type[? <: AnyKind]
[error]    |                        Required: scala.quoted.Type[T]
[error]    |
[error]    |                        where:    T is a type variable

Is there any way how to do this the right way? (edited)

new

1 Like

I found the solution, so if anybody is stuck on a similar issue:

method.tree.asInstanceOf[DefDef].returnTpt.tpe.asType match {
  case '[t] => 
    Super(This(cls), None).select(method).asExprOf[t]
}
2 Likes