Skip to content

Macro definitions don't see macro implementations in traits mixed into objects #7716

Closed
@anatoliykmetyuk

Description

@anatoliykmetyuk
import scala.quoted._

trait Foo:
  def mcrImpl1(e: Expr[Any])(using ctx: QuoteContext): Expr[Any] =
    '{println(s"Hello ${$e}")}

object Foo extends Foo:
  def mcrImpl2(e: Expr[Any])(using ctx: QuoteContext): Expr[Any] =
    '{println(s"Hello ${$e}")}

object Bar:
  import Foo._
  inline def mcr(e: => Any) = ${mcrImpl1('e)}

Says

-- Error: /Users/kmetiuk/Projects/scala3/pg/bug/Macro.scala:13:32 --------------
13 |  inline def mcr(e: => Any) = ${mcrImpl1('e)}
   |                                ^^^^^^^^^^^^
   | Malformed macro.
   |
   | Expected the splice ${...} to contain a single call to a static method.
1 error found

However, the following two definitions compile fine:

inline def mcr(e: => Any) = ${Foo.mcrImpl1('e)}
inline def mcr(e: => Any) = ${mcrImpl2('e)}

I would expect the original one also compile fine as semantically it is the same as ${Foo.mcrImpl1('e)} which works.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions