Skip to content

Macros do not expand TASTY macros if in any form of nesting #8866

Closed
@yilinwei

Description

@yilinwei

Minimized example

import scala.quoted._

object OtherMacro {

  def impl(using qctx: QuoteContext): Expr[Int] =
    '{ 42 }

  inline def apply = ${ OtherMacro.impl }

}

object Macro {

  def impl(using qctx: QuoteContext): Expr[Int] = {
    import qctx.tasty._
    import util._

    // Simply returning this term is OK
    // Select.unique(
    //   '{ OtherMacro }.unseal,
    //   "apply"
    // ).seal.cast[Int]

    let(
      Select.unique(
        '{ OtherMacro }.unseal,
        "apply"
      )
    )(identity).seal.cast[Int]
  }

  inline def apply = ${ Macro.impl }

}

Output

[error] 3 |  val a = Macro.apply
[error]   |          ^^^^^^^^^^^
[error]   |          method apply is declared as erased, but is in fact used

Expectation

Either TASTY reflect terms shouldn't be expanded, or possibly we can expand them explicitly? If you simply return the commented out code, the macro gets expanded.

If you have a quote with a macro it gets expanded as expected.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions