Frage

I'm working on a Scala macro where I want to match the type of a Symbol to a List[T], where the T is a given Type. I have the Type object of the T type parameter already.

It's easy to get the Type object of List[_]:

  val listType = c.weakTypeOf[List[_]]

with this I can already check the typeSignature

  sourceParam.typeSignature match {
    case paramType if paramType <:< listType =>
      ....
  }

But I want to check paramType with List[T], so how do I make a Type where I take the List[_] and some Type object and make it a new Type?

War es hilfreich?

Lösung

scala> val tpeList = typeOf[List[_]]
tpeList: reflect.runtime.universe.Type = scala.List[_]

scala> appliedType(tpeList, List(typeOf[Int]))
res0: reflect.runtime.universe.Type = scala.List[Int]
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top