[2.12.6] implicit macro not picked when used as class parameter


I have an implicit macro that produces a class

trait Generated[T] {
  def xxx:String
object M {
  implicit def gen[T]:Generated[T] = macro MI.genImpl[T]

import scala.reflect.macros.blackbox.Context
import scala.language.experimental.macros
class MI(val c: Context) { 
  def genImpl[T: c.WeakTypeTag]: c.Tree = { ... }

and a class that uses this macro:

class MacroUser[T](par1:String)(implicit g:Generated[T]) {}

When I try to use that class and put it inside trait or object all is well

package bar
import M._

case class T(dummy:Int)

//this works - macro is called
trait Wrap {
 class ConcreteUser1[T] extends MacroUser[T]("t")

//this does not work - implicit is not found, macro not called
class ConcreteUser2[T] extends MacroUser[T]("t")

Is it expected implicit macro behaviour ?

I’ve seen similar question Strange behaviour when implicit Macro used but also without answer

package foo


Just s suggestion for a test: have you tried making genImpl a simple function and
have it use the (val c: Context) parameter directly?

Also have you tried making MI a case class or provide a companion object with
the appropriate apply?



I didn’t try any of the approaches yet - I’ll try that later on.

I tried putting gen explicitly and it is fine

class ConcreteUser2[T] extends MacroUser[T]("t")(gen[T])

actual (non shortened) code is in

and here

I added X trait to just avoid the problem.