Skip to content

Commit 6f03643

Browse files
Merge pull request #13207 from KacperFKorban/scaladoc/fix-13203
Self types appear as inherited in docs and Docs leaking self type methods
2 parents 7389b63 + 23b7fb0 commit 6f03643

File tree

5 files changed

+33
-10
lines changed

5 files changed

+33
-10
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package tests.selftypes
2+
3+
class A:
4+
def a: Unit = ???
5+
6+
class C
7+
8+
class HasAnAndSelfType:
9+
self: A & C =>
10+
def b: Unit = ???
11+
12+
class HasASelfType:
13+
self: A =>
14+
def b: Unit = ???

scaladoc/src/dotty/tools/scaladoc/api.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ case class Member(
155155
members : Seq[Member] = Nil,
156156
directParents: Seq[LinkToType] = Nil,
157157
parents: Seq[LinkToType] = Nil,
158+
selfType: Option[LinkToType] = None,
158159
knownChildren: Seq[LinkToType] = Nil,
159160
companion: Option[DRI] = None,
160161
deprecated: Option[Annotation] = None,

scaladoc/src/dotty/tools/scaladoc/renderers/MemberRenderer.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,14 +349,22 @@ class MemberRenderer(signatureRenderer: SignatureRenderer)(using DocContext) ext
349349
div(link.kind.name," ", link.signature.map(renderElement))
350350
)))
351351

352+
def selfTypeList(list: List[LinkToType]): Seq[AppliedTag] =
353+
if list.isEmpty then Nil
354+
else Seq(div(cls := "symbol monospace") { list.map { link =>
355+
div(link.signature.map(renderElement))
356+
}})
357+
352358
val supertypes = signatureList(m.parents)
353359
val subtypes = signatureList(m.knownChildren)
360+
val selfType = selfTypeList(m.selfType.toList)
354361

355362
renderTabs(
356363
singleSelection = true,
357364
Tab("Graph", "graph", graphHtml, "showGraph"),
358365
Tab("Supertypes", "supertypes", supertypes),
359366
Tab("Known subtypes", "subtypes", subtypes),
367+
Tab("Self type", "selftype", selfType)
360368
)
361369

362370
private def buildDocumentableFilter = div(cls := "documentableFilter")(

scaladoc/src/dotty/tools/scaladoc/tasty/ClassLikeSupport.scala

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,18 @@ trait ClassLikeSupport:
8383
case (symbol, tpe) =>
8484
LinkToType(tpe.asSignature, symbol.dri, bareClasslikeKind(symbol))
8585
}
86-
val selfSiangture: DSignature = typeForClass(classDef).asSignature
86+
val selfType = classDef.self.map { (valdef: ValDef) =>
87+
val symbol = valdef.symbol
88+
val tpe = valdef.tpt.tpe
89+
LinkToType(tpe.asSignature, symbol.dri, Kind.Type(false, false, Seq.empty))
90+
}
91+
val selfSignature: DSignature = typeForClass(classDef).asSignature
8792

8893
val graph = HierarchyGraph.withEdges(
89-
getSupertypesGraph(classDef, LinkToType(selfSiangture, classDef.symbol.dri, bareClasslikeKind(classDef.symbol)))
94+
getSupertypesGraph(classDef, LinkToType(selfSignature, classDef.symbol.dri, bareClasslikeKind(classDef.symbol)))
9095
)
9196

92-
val baseMember = mkMember(classDef.symbol, kindForClasslike(classDef), selfSiangture)(
97+
val baseMember = mkMember(classDef.symbol, kindForClasslike(classDef), selfSignature)(
9398
modifiers = modifiers,
9499
graph = graph,
95100
deprecated = classDef.symbol.isDeprecated()
@@ -227,6 +232,7 @@ trait ClassLikeSupport:
227232
members = classDef.extractPatchedMembers.sortBy(m => (m.name, m.kind.name)),
228233
directParents = classDef.getParentsAsLinkToTypes,
229234
parents = supertypes,
235+
selfType = selfType,
230236
companion = classDef.getCompanion
231237
)
232238

scaladoc/src/dotty/tools/scaladoc/tasty/SyntheticSupport.scala

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,7 @@ object SyntheticsSupport:
7474
import dotty.tools.dotc
7575
given ctx: dotc.core.Contexts.Context = quotes.asInstanceOf[scala.quoted.runtime.impl.QuotesImpl].ctx
7676
val sym = rsym.asInstanceOf[dotc.core.Symbols.Symbol]
77-
// `lookupPrefix` is private in `QuotesImpl#SymbolMethods`
78-
val lookupPrefix =
79-
if sym.isClass then
80-
sym.thisType
81-
else
82-
sym.namedType
83-
lookupPrefix.allMembers.iterator.map(_.symbol)
77+
sym.namedType.allMembers.iterator.map(_.symbol)
8478
.collect {
8579
case sym if
8680
(!sym.is(dotc.core.Flags.ModuleVal) || sym.is(dotc.core.Flags.Given)) &&

0 commit comments

Comments
 (0)