Frage

I have a quoasiquote matcher where q"someMethod[$ts]()" where def someMethod[I <: shapeless.HList]()".

Printing ts gives:

List(shapeless.HNil)

or, e.g.

List(String, Int)

Then I try to assign:

val types: List[scala.reflect.api.Types.Type] = ts

that causes compiler error:

[error] type mismatch;
[error]  found   : List[_125.u.Tree] where val _125: scala.reflect.api.QuasiquoteCompat.TypeAppliedExtractor{val u: OpTreeContext.this.c.universe.type}
[error]  required: List[Context.this.c.universe.Type]

How to compose List[scala.reflect.api.Types.Type] from ts?

War es hilfreich?

Lösung

As your error message states, ts is a list of trees. More specifically, these will be type trees, and you can extract their types with the tpe method:

val types: List[scala.reflect.api.Types#Type] = ts.map(_.tpe)

Note that I'm using a type projection, since Types is neither a package nor an object, so Types.Type won't work.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top