Skip to content

Commit c657bbf

Browse files
authored
Merge pull request #1829 from dotty-staging/fix-#1794
Fix #1794: handle TermRef result types in dottydoc
2 parents 52c869c + 6dd758e commit c657bbf

File tree

4 files changed

+43
-28
lines changed

4 files changed

+43
-28
lines changed

compiler/test/dotc/scala-collections.blacklist

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,5 @@
222222
# | result type of implicit definition needs to be given explicitly
223223

224224

225-
../scala-scala/src/library/scala/sys/SystemProperties.scala
226-
# crashes on dotty.tools.dottydoc.TestWhitelistedCollections.arrayHasDocumentation
227-
228225
../scala-scala/src/library/scala/util/Sorting.scala
229226
# assertion failed: invalid prefix ImplicitMethodType(List(ord), List(RefinedType(TypeRef(ThisType(TypeRef(NoPrefix,math)),Ordering), scala$math$Ordering$$T, TypeAlias(TypeRef(NoPrefix,K), 0))), RefinedType(TypeRef(ThisType(TypeRef(NoPrefix,math)),Ordering), scala$math$Ordering$$T, TypeAlias(TypeRef(NoPrefix,K), 0)))

compiler/test/dotc/scala-collections.whitelist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@
386386

387387
../scala-scala/src/library/scala/compat/Platform.scala
388388

389+
../scala-scala/src/library/scala/sys/SystemProperties.scala
389390
../scala-scala/src/library/scala/sys/package.scala
390391
../scala-scala/src/library/scala/sys/Prop.scala
391392
../scala-scala/src/library/scala/sys/PropImpl.scala

doc-tool/src/dotty/tools/dottydoc/core/DocASTPhase.scala

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import dotc.CompilationUnit
88
import dotc.config.Printers.dottydoc
99
import dotc.core.Contexts.Context
1010
import dotc.core.Comments.ContextDocstrings
11+
import dotc.core.Types.NoType
1112
import dotc.core.Phases.Phase
1213
import dotc.core.Symbols.{ Symbol, NoSymbol }
1314

@@ -44,32 +45,35 @@ class DocASTPhase extends Phase {
4445
}
4546

4647
def membersFromSymbol(sym: Symbol): List[Entity] = {
47-
val defs = sym.info.bounds.hi.membersBasedOnFlags(Flags.Method, Flags.Synthetic | Flags.Private)
48-
.filterNot(_.symbol.owner.name.show == "Any")
49-
.map { meth =>
50-
DefImpl(
51-
meth.symbol,
52-
meth.symbol.name.show,
53-
Nil,
54-
path(meth.symbol),
55-
returnType(meth.info),
56-
typeParams(meth.symbol),
57-
paramLists(meth.info),
58-
implicitlyAddedFrom = Some(returnType(meth.symbol.owner.info))
48+
if (sym.info ne NoType) {
49+
val defs = sym.info.bounds.hi.membersBasedOnFlags(Flags.Method, Flags.Synthetic | Flags.Private)
50+
.filterNot(_.symbol.owner.name.show == "Any")
51+
.map { meth =>
52+
DefImpl(
53+
meth.symbol,
54+
meth.symbol.name.show,
55+
Nil,
56+
path(meth.symbol),
57+
returnType(meth.info),
58+
typeParams(meth.symbol),
59+
paramLists(meth.info),
60+
implicitlyAddedFrom = Some(returnType(meth.symbol.owner.info))
61+
)
62+
}.toList
63+
64+
val vals = sym.info.fields.filterNot(_.symbol.is(Flags.Private | Flags.Synthetic)).map { value =>
65+
ValImpl(
66+
value.symbol,
67+
value.symbol.name.show,
68+
Nil, path(value.symbol),
69+
returnType(value.info),
70+
implicitlyAddedFrom = Some(returnType(value.symbol.owner.info))
5971
)
60-
}.toList
61-
62-
val vals = sym.info.fields.filterNot(_.symbol.is(Flags.Private | Flags.Synthetic)).map { value =>
63-
ValImpl(
64-
value.symbol,
65-
value.symbol.name.show,
66-
Nil, path(value.symbol),
67-
returnType(value.info),
68-
implicitlyAddedFrom = Some(returnType(value.symbol.owner.info))
69-
)
70-
}
72+
}
7173

72-
defs ++ vals
74+
defs ++ vals
75+
}
76+
else Nil
7377
}
7478

7579

doc-tool/src/dotty/tools/dottydoc/model/factories.scala

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import dotc.core.TypeApplications._
99
import dotc.core.Contexts.Context
1010
import dotc.core.Symbols.{ Symbol, ClassSymbol }
1111
import dotty.tools.dotc.core.SymDenotations._
12+
import dotty.tools.dotc.config.Printers.dottydoc
1213
import dotty.tools.dotc.core.Names.TypeName
1314
import dotc.ast.Trees._
1415

@@ -105,6 +106,17 @@ object factories {
105106
else paramName
106107

107108
typeRef(name)
109+
case tr: TermRef =>
110+
/** A `TermRef` appears in the return type in e.g:
111+
* ```
112+
* def id[T](t: T): t.type = t
113+
* ```
114+
*/
115+
val name = tr.show
116+
if (!name.endsWith(".type"))
117+
ctx.warning(s"unhandled return type found: $tr")
118+
119+
typeRef(name, params = params)
108120
}
109121

110122
expandTpe(t)
@@ -154,7 +166,8 @@ object factories {
154166

155167
case annot: AnnotatedType => paramLists(annot.tpe)
156168
case (_: PolyParam | _: RefinedType | _: TypeRef | _: ThisType |
157-
_: ExprType | _: OrType | _: AndType | _: HKApply) => Nil // return types should not be in the paramlist
169+
_: ExprType | _: OrType | _: AndType | _: HKApply | _: TermRef) =>
170+
Nil // return types should not be in the paramlist
158171
}
159172

160173
def superTypes(t: Tree)(implicit ctx: Context): List[MaterializableLink] = t.symbol.denot match {

0 commit comments

Comments
 (0)