Skip to content
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

Self types appear as inherited in docs and Docs leaking self type methods #13207

Merged
merged 5 commits into from
Aug 2, 2021
Merged
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
14 changes: 14 additions & 0 deletions scaladoc-testcases/src/tests/selftypes.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package tests.selftypes

class A:
def a: Unit = ???

class C

class HasAnAndSelfType:
self: A & C =>
def b: Unit = ???

class HasASelfType:
self: A =>
def b: Unit = ???
1 change: 1 addition & 0 deletions scaladoc/src/dotty/tools/scaladoc/api.scala
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ case class Member(
members : Seq[Member] = Nil,
directParents: Seq[LinkToType] = Nil,
parents: Seq[LinkToType] = Nil,
selfType: Option[LinkToType] = None,
knownChildren: Seq[LinkToType] = Nil,
companion: Option[DRI] = None,
deprecated: Option[Annotation] = None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,14 +349,22 @@ class MemberRenderer(signatureRenderer: SignatureRenderer)(using DocContext) ext
div(link.kind.name," ", link.signature.map(renderElement))
)))

def selfTypeList(list: List[LinkToType]): Seq[AppliedTag] =
if list.isEmpty then Nil
else Seq(div(cls := "symbol monospace") { list.map { link =>
div(link.signature.map(renderElement))
}})

val supertypes = signatureList(m.parents)
val subtypes = signatureList(m.knownChildren)
val selfType = selfTypeList(m.selfType.toList)

renderTabs(
singleSelection = true,
Tab("Graph", "graph", graphHtml, "showGraph"),
Tab("Supertypes", "supertypes", supertypes),
Tab("Known subtypes", "subtypes", subtypes),
Tab("Self type", "selftype", selfType)
)

private def buildDocumentableFilter = div(cls := "documentableFilter")(
Expand Down
12 changes: 9 additions & 3 deletions scaladoc/src/dotty/tools/scaladoc/tasty/ClassLikeSupport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,18 @@ trait ClassLikeSupport:
case (symbol, tpe) =>
LinkToType(tpe.asSignature, symbol.dri, bareClasslikeKind(symbol))
}
val selfSiangture: DSignature = typeForClass(classDef).asSignature
val selfType = classDef.self.map { (valdef: ValDef) =>
val symbol = valdef.symbol
val tpe = valdef.tpt.tpe
LinkToType(tpe.asSignature, symbol.dri, Kind.Type(false, false, Seq.empty))
}
val selfSignature: DSignature = typeForClass(classDef).asSignature

val graph = HierarchyGraph.withEdges(
getSupertypesGraph(classDef, LinkToType(selfSiangture, classDef.symbol.dri, bareClasslikeKind(classDef.symbol)))
getSupertypesGraph(classDef, LinkToType(selfSignature, classDef.symbol.dri, bareClasslikeKind(classDef.symbol)))
)

val baseMember = mkMember(classDef.symbol, kindForClasslike(classDef), selfSiangture)(
val baseMember = mkMember(classDef.symbol, kindForClasslike(classDef), selfSignature)(
modifiers = modifiers,
graph = graph,
deprecated = classDef.symbol.isDeprecated()
Expand Down Expand Up @@ -226,6 +231,7 @@ trait ClassLikeSupport:
members = classDef.extractPatchedMembers.sortBy(m => (m.name, m.kind.name)),
directParents = classDef.getParentsAsLinkToTypes,
parents = supertypes,
selfType = selfType,
companion = classDef.getCompanion
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,7 @@ object SyntheticsSupport:
import dotty.tools.dotc
given ctx: dotc.core.Contexts.Context = quotes.asInstanceOf[scala.quoted.runtime.impl.QuotesImpl].ctx
val sym = rsym.asInstanceOf[dotc.core.Symbols.Symbol]
// `lookupPrefix` is private in `QuotesImpl#SymbolMethods`
val lookupPrefix =
if sym.isClass then
sym.thisType
else
sym.namedType
lookupPrefix.allMembers.iterator.map(_.symbol)
sym.namedType.allMembers.iterator.map(_.symbol)
.collect {
case sym if
(!sym.is(dotc.core.Flags.ModuleVal) || sym.is(dotc.core.Flags.Given)) &&
Expand Down