Question

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?

Was it helpful?

Solution

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]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top