1

When inspecting any "regularly" created module, e.g. object Foo, there is a non empty body which looks like this:

def <init>() = {
  super.<init>();
  ()
}

Apparently that's the special constructor used to initialise the module.

I want to synthetically create a ModuleDef, so how do I define a corresponding tree for that constructor for its Template? Is there a utility method in the macro universe / context I can use?


Edit: A "regular" object's template body looks like the following, using showRaw:

DefDef(Modifiers(), nme.CONSTRUCTOR, List(), List(List()), TypeTree(),
  Block(List(pendingSuperCall), Literal(Constant(())))))))

After type checking the pendingSuperCall becomes

Apply(Select(Super(This(TypeName("Foo")), tpnme.EMPTY), nme.CONSTRUCTOR), List())

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.