Skip to content

Add typeRef and termRef to Reflection #9707

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

Conversation

nicolasstucki
Copy link
Contributor

No description provided.

@nicolasstucki nicolasstucki self-assigned this Sep 2, 2020
@nicolasstucki nicolasstucki force-pushed the add-typeRef-and-termRef branch from 50e4533 to ca98cff Compare September 3, 2020 07:06
@nicolasstucki nicolasstucki marked this pull request as ready for review September 3, 2020 08:20
def Symbol_typeRef(self: Symbol)(using Context): TypeRef

/** Term referene to the symbol */
def Symbol_termRef(self: Symbol)(using Context): TermRef
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The two methods are rarely used in the compiler. I'd suggest only expose them when there is a clear use case.

val qtp: quoted.Type[T] = tp0.seal.asInstanceOf[quoted.Type[T]]
given qtp.type = qtp
'[Seq[T]].unseal.tpe
Symbol.requiredClass("scala.collection.immutable.Seq").typeRef.appliedTo(tp0)
Copy link
Contributor

@liufengyun liufengyun Sep 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems for this typical usage, an API like def fromPath(path: String): Type is more friendly:

Type.fromPath("scala.collection.immutable.Seq").appliedTo(tp0)
// or
Type.staticRef("scala.collection.immutable.Seq").appliedTo(tp0)

The compiler API can keep the same, the user API can be a little different. This way, we also defend against compiler changes from meta-programmers.

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 this pull request may close these issues.

2 participants