This is another problem which blocks izumi-reflect reimplementation for Dotty.
Let's assume that we have the following definitions:
trait X[+_]
trait A[+F[+_]]
Having AppliedType for A[X[Int]] I need to be able to access it's type constructor, enumerate parameters and obtain variance flags. Essentially I need to get something like List(TypeParameter(F, Covariant))
So far I've found the only (insane) way to access something which looks like a type constructor:
val tycontree = a.tycon.asInstanceOf[TypeRef].typeSymbol.tree.asInstanceOf[TypeDef].rhs.asInstanceOf[TypeTree]
val params = try {
tycontree match {
case d: {def constr: DefDef} =>
d.constr.typeParams
case o =>
}
} catch {
case t: Throwable =>
}
Though this way I cannot extract type parameter declarations - all the values returned by typeParams are instances of TypeBounds with no variance information attached.
See also: 7mind/dotty-typetag-research#2
@nicolasstucki could you check this issue please?
@smarter how would we do this properly within the compiler?
@nicolasstucki If I have a symbol for trait A[+F[+_]], I can call SymDenotation#typeParams to get the symbol of F, then check the .is(Covariant) / .is(Contravariant) flags on that symbol.
(If I want the variance of the parameter of F itself, then I need to get the info of F which should be a TypeBounds whose upper-bound is an HKTypeLambda, once I get that I can finally call HKTypeLambda#declaredVariances on it.)
As for #8514, big 馃憤 on this from me and other ZIO contributors / users eager to fully utilize the new environment encoding on Scala 3.
Most helpful comment
@nicolasstucki If I have a symbol for
trait A[+F[+_]], I can callSymDenotation#typeParamsto get the symbol ofF, then check the.is(Covariant)/.is(Contravariant)flags on that symbol.(If I want the variance of the parameter of
Fitself, then I need to get theinfoofFwhich should be aTypeBoundswhose upper-bound is anHKTypeLambda, once I get that I can finally callHKTypeLambda#declaredVarianceson it.)