macwire icon indicating copy to clipboard operation
macwire copied to clipboard

Wire from parent scope

Open mbore opened this issue 3 years ago • 2 comments

Depends on lampepfl/dotty#13105

mbore avatar Jul 23 '21 06:07 mbore

@mbore

import scala.quoted.*

object Macros {
  inline def f(): String = ${ fImpl }

  def fImpl(using q: Quotes): Expr[String] = {
    import q.reflect.*

    val classSymbol = Symbol.spliceOwner.owner.owner
    classSymbol.memberMethods.find(_.name == "s") match {
      case None => '{""}
      case Some(s) =>
        val t = Select(This(classSymbol), s).appliedToArgss(Nil)
        t.asExprOf[String]
    }
  }
}

This could be used here to access this ref. Ref can only ref to a term, s is not a term here.

jilen avatar Jul 06 '23 09:07 jilen

Seems already resolved.

jilen avatar Jul 07 '23 05:07 jilen