Closed
Description
Compiler version
3.5.1
Minimized example
Mill's Cross Modules are implemented with a macro that generates a class, and a factory function that creates a new instance of the class given some context.
// mill definitions (simplified)
package mill
trait Module(using Context)
object Cross:
trait Module[String] extends mill.Module:
def crossValue: String
// user code
trait MyCrossModule extends Cross.Module[String]
object myCross extends Cross[MyCrossModule]("foo", "bar")
// simplified generated code as part of implicit conversion from `"foo"` to `Factory[MyCrossModule]`
factoryArgs.map[MyCrossModule]({ (arg: "foo") =>
class C(ctx: Context) extends MyCrossModule with mill.Module(using ctx) {
def crossValue: String = arg
}
(classOf[C], ctx => new C(ctx))
})
The new class has to be generated via Macro, not quotes and splices, because the Specific cross module trait is not known statically.
The problem is that there is no way via Symbol.newClass
to add the necessary (ctx: Context)
parameter to the generated class C
Expectation
Allow to customise the parameters of the class, even if its just single term parameter list, I think generic is less needed because the macro can specialise the types.