Skip to content

Add TypeRepr.memberInfo, Symbol.tpe, Symbol.typeParams to reflection API #13395

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
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1743,6 +1743,8 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
dotc.core.Types.decorateTypeApplications(self).appliedTo(targ)
def appliedTo(targs: List[TypeRepr]): TypeRepr =
dotc.core.Types.decorateTypeApplications(self).appliedTo(targs)
def memberInfo(sym: Symbol): TypeRepr =
self.memberInfo(sym)
end extension
end TypeReprMethods

Expand Down Expand Up @@ -2610,6 +2612,8 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
def companionClass: Symbol = self.denot.companionClass
def companionModule: Symbol = self.denot.companionModule
def children: List[Symbol] = self.denot.children
def tpe: TypeRepr = self.typeRef
Copy link
Contributor

Choose a reason for hiding this comment

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

This was in #9707

def typeParams: List[Symbol] = self.denot.typeParams

def show(using printer: Printer[Symbol]): String = printer.show(self)

Expand Down
9 changes: 9 additions & 0 deletions library/src/scala/quoted/Quotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2535,6 +2535,9 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
/** The current type applied to given type arguments: `this[targ0, ..., targN]` */
def appliedTo(targs: List[TypeRepr]): TypeRepr

/** Member info of `sym` as seen from the TypeRepr */
def memberInfo(sym: Symbol): TypeRepr

end extension
}

Expand Down Expand Up @@ -3741,6 +3744,12 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>

/** Case class or case object children of a sealed trait or cases of an `enum`. */
def children: List[Symbol]

/** Type of the symbol */
def tpe: TypeRepr

/** Type parameters of the symbol */
def typeParams: List[Symbol]
end extension
}

Expand Down
3 changes: 3 additions & 0 deletions project/MiMaFilters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@ object MiMaFilters {
exclude[ReversedMissingMethodProblem]("scala.quoted.Quotes#reflectModule.TypedOrTestTypeTest"),
exclude[ReversedMissingMethodProblem]("scala.quoted.Quotes#reflectModule.TypedOrTest"),
exclude[ReversedMissingMethodProblem]("scala.quoted.Quotes#reflectModule.TypedOrTestMethods"),
exclude[ReversedMissingMethodProblem]("scala.quoted.Quotes#reflectModule#TypeReprMethods.memberInfo"),
exclude[ReversedMissingMethodProblem]("scala.quoted.Quotes#reflectModule#SymbolMethods.tpe"),
exclude[ReversedMissingMethodProblem]("scala.quoted.Quotes#reflectModule#SymbolMethods.typeParams"),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ trait ClassLikeSupport:
val tpe = valdef.tpt.tpe
LinkToType(tpe.asSignature, symbol.dri, Kind.Type(false, false, Seq.empty))
}
val selfSignature: DSignature = typeForClass(classDef).asSignature
val selfSignature: DSignature = classDef.symbol.tpe
.appliedTo(classDef.symbol.typeParams.map(_.tpe))
.asSignature

val graph = HierarchyGraph.withEdges(
getSupertypesGraph(classDef, LinkToType(selfSignature, classDef.symbol.dri, bareClasslikeKind(classDef.symbol)))
Expand Down Expand Up @@ -631,7 +633,7 @@ trait ClassLikeSupport:


def unwrapMemberInfo(c: ClassDef, symbol: Symbol): MemberInfo =
val baseTypeRepr = memberInfo(c, symbol)
val baseTypeRepr = c.symbol.tpe.memberInfo(symbol)

def isSyntheticEvidence(name: String) =
if !name.startsWith(NameKinds.EvidenceParamName.separator) then false else
Expand Down