Scala 3 Macro Reflection: how to instantiate an anonymous class?


This is a follow up question from this question. Given the class:

  trait SelectableBase[C <: Tuple] extends Selectable:
    val cols : C

    transparent inline def selectDynamic(name: String): Any = ???
    def applyDynamic(name: String)(args: Any*): Any = ???

I would like to instantiate an anonymous class via reflection so as to create a number of members “dynamically”. Here is an example:

    new SelectableBase[(String,Int,Char)](){
      // Must assign the values before using them, otherwise we get a compile error
      val cols = ("D", 3, 'B')
      val name: String = cols(0)
      val age: Int = cols(1)
      val sex: Char = cols(2)

I know how to create and instantiate a standard class via reflection, however it is equivalent to something like:

  class Struct extends java.lang.Object with examples.instantiate.MyMacro5Vals.SelectableBase {
    val field: scala.Int = 3

  (new Struct(): Struct)

which is not the same for the compiler, because the use of Selectable differs.

Any pointers and suggestions are welcome.