title: How do I add a no-arg constructor to a Scala case class with a macro annotation?
body: <p>I'm trying to answer <a href="https://stackoverflow.com/questions/13812172/how-can-i-create-an-instance-of-a-case-class-with-constructor-arguments-with-no">this question</a>.</p>
  
  <p>Instead of writing:</p>
  
  <pre><code>case class Person(name: String, age: Int) {
    def this() = this("",1)
  }
  </code></pre>
  
  <p>I thought I'd use macro annotations to expand it from:</p>
  
  <pre><code>@Annotation
  case class Person(name: String, age: Int)
  </code></pre>
  
  <p>So I tried adding the new constructor as a plain-old <code>DefDef</code> using quasiquotes in a macro annotation's impl, like:</p>
  
  <pre><code>val newCtor = q"""def this() = this("", 1)"""
  val newBody = body :+ newCtor
  q"$mods class $name[..$tparams](..$first)(...$rest) extends ..$parents { $self =&gt; ..$newBody }"
  </code></pre>
  
  <p>But that returns an error: <code>called constructor's definition must precede calling constructor's definition</code></p>
  
  <p>Is there a way to fix that? What did I miss?</p>
  
  <p>Thanks for taking a look,
  -Julian</p>