title: Why does the Scala Macro for case class copy fail?
body: <p>I have about 24 Case classes that I need to programatically enhance by changing several common elements prior to serialization in a datastore that doesn't support joins. Since case classes don't have a trait defined for the copy(...) constructor, I have been attempting to use Macros - As a base I've looked at 
  <a href="https://stackoverflow.com/questions/13446528/howto-model-named-parameters-in-method-invocations-with-scala-macros/13447439#13447439">this post documenting a macro</a> and come up with this macro: </p>
  
  <p>When I try to compile, I get the following: </p>
  
  <pre><code>import java.util.UUID
  
  import org.joda.time.DateTime
  import scala.language.experimental.macros
  
  
  trait RecordIdentification {
    val receiverId: Option[String]
    val transmitterId: Option[String]
    val patientId: Option[UUID]
    val streamType: Option[String]
    val sequenceNumber: Option[Long]
    val postId: Option[UUID]
    val postedDateTime: Option[DateTime]
  }
  
  object WithRecordIdentification {
    import scala.reflect.macros.Context
  
    def withId[T, I](entity: T, id: I): T = macro withIdImpl[T, I]
  
    def withIdImpl[T: c.WeakTypeTag, I: c.WeakTypeTag](c: Context)(
      entity: c.Expr[T], id: c.Expr[I]
    ): c.Expr[T] = {
      import c.universe._
  
      val tree = reify(entity.splice).tree
      val copy = entity.actualType.member(newTermName("copy"))
  
      val params = copy match {
        case s: MethodSymbol if (s.paramss.nonEmpty) =&gt; s.paramss.head
        case _ =&gt; c.abort(c.enclosingPosition, "No eligible copy method!")
      }
  
      c.Expr[T](Apply(
        Select(tree, copy),
        AssignOrNamedArg(Ident("postId"), reify(id.splice).tree) ::
        AssignOrNamedArg(Ident("patientId"), reify(id.splice).tree) ::
        AssignOrNamedArg(Ident("receiverId"), reify(id.splice).tree) ::
        AssignOrNamedArg(Ident("transmitterId"), reify(id.splice).tree) ::
        AssignOrNamedArg(Ident("sequenceNumber"), reify(id.splice).tree) :: Nil
      ))
    }
  }
  </code></pre>
  
  <p>And I invoke it with something like: </p>
  
  <pre><code>class GenericAnonymizer[A &lt;: RecordIdentification]() extends Schema {
    def anonymize(dataPost: A, header: DaoDataPostHeader): A = WithRecordIdentification.withId(dataPost, header)
  }
  </code></pre>
  
  <p>But I get a compile error: </p>
  
  <pre><code>Error:(44, 71) type mismatch;
   found   : com.dexcom.rt.model.DaoDataPostHeader
   required: Option[String]
      val copied = WithRecordIdentification.withId(sampleGlucoseRecord, header)
  Error:(44, 71) type mismatch;
   found   : com.dexcom.rt.model.DaoDataPostHeader
   required: Option[java.util.UUID]
      val copied = WithRecordIdentification.withId(sampleGlucoseRecord, header)
  Error:(44, 71) type mismatch;
   found   : com.dexcom.rt.model.DaoDataPostHeader
   required: Option[Long]
      val copied = WithRecordIdentification.withId(sampleGlucoseRecord, header)
  </code></pre>
  
  <p>I'm not quite sure how to change the macro to support multiple parameters... any sage advice? </p>