title: Troubles with getting case class fields via reflection
body: <p>I have a scala code: trait model and its implementation case class Category with custom annotation which i wish to read later</p>
  <pre class="lang-scala prettyprint-override"><code>import scala.annotation.StaticAnnotation
  class ExtraFields() extends StaticAnnotation
  
  trait Model {}
  
  case class MyCategory( id: Option[Int],
                       name: String,
                       level: Option[Int],
  
                       @ExtraFields
                       parent: Option[MyCategory] = None
                     ) extends Model {
  
  }
  </code></pre>
  <p>and i have trait DBModel and its implementation MyCategoryModel. And i pass MyCategory as type parameter to DBModel</p>
  <pre class="lang-scala prettyprint-override"><code>trait DBModel[T &lt;: Model] {
    lazy val fields = getClassFields[T]
    lazy val fields2 = getClassFields2[T]
  }
  
  object MyCategoryModel extends DBModel[MyCategory] {
    def getFields = fields
    def getFields2 = fields2
  }
  </code></pre>
  <p>i want trait DBModel to read fields of case class passed as T parameter, so i call two functions</p>
  <pre class="lang-scala prettyprint-override"><code>def getClassFields[T] = {
    symbolOf[T].asClass.primaryConstructor
      .typeSignature.paramLists.head.map {v =&gt;
        v.name.toString -&gt; v.annotations
      }
  }
  
  def getClassFields2[T: TypeTag]: Iterable[(String, List[universe.Annotation])] =
    typeOf[T].members.collect {
      case m: MethodSymbol if m.isCaseAccessor =&gt;
        m.name.toString -&gt; m.annotations
    }
  </code></pre>
  <p>but none of them is working</p>
  <pre class="lang-scala prettyprint-override"><code>val res = MyCategoryModel.getFields // runtime exception: free type T is not a class
  val res2 = MyCategoryModel.getFields2 // compile error: No TypeTag available for T
  </code></pre>
  <p>If i call them directly</p>
  <pre class="lang-scala prettyprint-override"><code>getClassFields[MyCategory]
  getClassFields2[MyCategory]
  </code></pre>
  <p>for a first function i get the same error, for the second i get result but universe.annotations can not see my ExtraFields annotation, returning empty lists for each of fields</p>
  <p>Could you please explain this black magic and how to conqure it in my case
  Thank you</p>
  <p>UPD playground <a href="https://scastie.scala-lang.org/DTTTyA0CSTSZ0Vj7KFW6Hw" rel="nofollow noreferrer">https://scastie.scala-lang.org/DTTTyA0CSTSZ0Vj7KFW6Hw</a></p>