title: Scala 2.11 Macros - Parse JDBC row to case class
body: <p>I'm trying to make a macro for my Play Framework project (2.3.7). I'm trying to make it easy to map an anorm Row to a case class. When I try to compile the attached code, I am getting the following exception:</p>
  
  <pre><code>[error] ***:15: exception    during macro expansion:
  [error] java.util.NoSuchElementException: None.get
  [error]     at scala.None$.get(Option.scala:322)
  [error]     at scala.None$.get(Option.scala:320)
  [error]     at ***.ModelMacros$.reads(ModelMacros.scala:29)
  
  import anorm._
  
  import scala.reflect.macros.whitebox
  import scala.language.experimental.macros
  
  object ModelMacros {
    implicit def sqlMapper[T]: Row =&gt; T = macro reads[T]
  
    def reads[T: c.WeakTypeTag](c: whitebox.Context): c.Expr[Row =&gt; T] = {
      import c.universe._
  
      val t = weakTypeOf[T]
      val companion = t.typeSymbol.companion
  
      val fields = t.declarations.collectFirst {
        case m: MethodSymbol if m.isPrimaryConstructor ⇒ m
      }.get.paramLists.head
  
      val fromMapParams = fields.map { field =&gt;
        val name = field.name.toTermName
        val decoded = name.decodedName.toString
        val returnType = t.decl(name).typeSignature
  
        val fixedName = camelToUnderscores(decoded)
  
        q"row[$returnType]($fixedName)"
      }
  
      c.Expr[Row =&gt; T] {
        q"""
          { row =&gt; $companion(..$fromMapParams) }
        """
      }
    }
  }
  </code></pre>
  
  <p>I do not understand what to do to get the generic T to reflect appropriately. Any help would be greatly appreciated. Thanks!</p>