Solved: Can Scala 3 macros be used with using/given instances?

I am trying to add a name to an instance, based on the the assigned variable name, as shown below:


  inline def transformX(from: Seq[Int]): Table.Ints =
    transformInts(from)

   ...

    val c0 = transformX( Seq(100,200,300,400) )

This will produce the intended result:

Ints("c0", Array(100,200,300,400))

I used part of the code in this StackOveflow question to get this working. I am only using the first part of the code that works on the example above. However, I want to use this via a type class. More concretely I have:

  trait Transformer[From, To]:
    def transform(from: From): To

  extension [T] (from: Seq[T])
    def toColumn[C](using t: Transformer[Seq[T], C]): C = 
      t.transform(from)

  given integers: Transformer[Seq[Int], Table.Ints] with
    def transform(from: Seq[Int]): Table.Ints =
      transformInts(from)

  ...
     val c1 = Seq(100,200,300,400).toColumn

Now when I compile the code, the macro is only invoked once at the site:

    def transform(from: Seq[Int]): Table.Ints =
      transformInts(from)

and I get the owner name transform. Irrespective of whether or not I use the type class, my debug prints only show up at the start and method definition position, and not at the call site. I have tried in-lining the transform call, but nothing changes.

Does anyone know if their is some restriction on the use of macros in “using” instances?

TIA

Short answer is, yes. Apparently I also need to add an inline to the extension method, as shown below:

  trait Transformer[From, To]:
    def transform(from: From): To

  extension [T] (from: Seq[T])
    // IMPORTANT: this must be inlined so that the macro is invoked at the call site
    inline def toColumn[C](using t: Transformer[Seq[T], C]): C = 
      t.transform(from)

  // IMPORTANT: this does NOT have to be inlined so that the macro is invoked at the call site
  inline given integers: Transformer[Seq[Int], Table.Ints] with
    // IMPORTANT: this must be inlined so that the macro is invoked at the call site
    inline def transform(from: Seq[Int]): Table.Ints =
      transformInts(from)

Still cannot figure out why the initial call to the macro at the definition site, but the code overall works.