Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symbol.newClass does not support class parameters #21739

Open
bishabosha opened this issue Oct 9, 2024 · 0 comments
Open

Symbol.newClass does not support class parameters #21739

bishabosha opened this issue Oct 9, 2024 · 0 comments
Assignees
Labels
area:metaprogramming:reflection Issues related to the quotes reflection API itype:enhancement

Comments

@bishabosha
Copy link
Member

bishabosha commented Oct 9, 2024

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.

@bishabosha bishabosha added stat:needs triage Every issue needs to have an "area" and "itype" label itype:enhancement area:metaprogramming:reflection Issues related to the quotes reflection API and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Oct 9, 2024
@jchyb jchyb self-assigned this Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:metaprogramming:reflection Issues related to the quotes reflection API itype:enhancement
Projects
None yet
Development

No branches or pull requests

2 participants