Skip to content

TASTY: no way to access type constructor of an AppliedType and explore its argument variance #8520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pshirshov opened this issue Mar 11, 2020 · 4 comments · Fixed by #8962
Closed
Assignees

Comments

@pshirshov
Copy link
Contributor

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

@pshirshov
Copy link
Contributor Author

pshirshov commented Mar 11, 2020

@nicolasstucki could you check this issue please?

@nicolasstucki
Copy link
Contributor

@smarter how would we do this properly within the compiler?

@smarter
Copy link
Member

smarter commented Mar 11, 2020

@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.)

@jdegoes
Copy link

jdegoes commented Apr 1, 2020

As for #8514, big 👍 on this from me and other ZIO contributors / users eager to fully utilize the new environment encoding on Scala 3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants