Skip to content

Fix #1794: handle TermRef result types in dottydoc #1829

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

Merged
merged 1 commit into from
Dec 19, 2016
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
3 changes: 0 additions & 3 deletions compiler/test/dotc/scala-collections.blacklist
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,5 @@
# | result type of implicit definition needs to be given explicitly


../scala-scala/src/library/scala/sys/SystemProperties.scala
# crashes on dotty.tools.dottydoc.TestWhitelistedCollections.arrayHasDocumentation

../scala-scala/src/library/scala/util/Sorting.scala
# 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)))
1 change: 1 addition & 0 deletions compiler/test/dotc/scala-collections.whitelist
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@

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

../scala-scala/src/library/scala/sys/SystemProperties.scala
../scala-scala/src/library/scala/sys/package.scala
../scala-scala/src/library/scala/sys/Prop.scala
../scala-scala/src/library/scala/sys/PropImpl.scala
Expand Down
52 changes: 28 additions & 24 deletions doc-tool/src/dotty/tools/dottydoc/core/DocASTPhase.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import dotc.CompilationUnit
import dotc.config.Printers.dottydoc
import dotc.core.Contexts.Context
import dotc.core.Comments.ContextDocstrings
import dotc.core.Types.NoType
import dotc.core.Phases.Phase
import dotc.core.Symbols.{ Symbol, NoSymbol }

Expand Down Expand Up @@ -44,32 +45,35 @@ class DocASTPhase extends Phase {
}

def membersFromSymbol(sym: Symbol): List[Entity] = {
val defs = sym.info.bounds.hi.membersBasedOnFlags(Flags.Method, Flags.Synthetic | Flags.Private)
.filterNot(_.symbol.owner.name.show == "Any")
.map { meth =>
DefImpl(
meth.symbol,
meth.symbol.name.show,
Nil,
path(meth.symbol),
returnType(meth.info),
typeParams(meth.symbol),
paramLists(meth.info),
implicitlyAddedFrom = Some(returnType(meth.symbol.owner.info))
if (sym.info ne NoType) {
val defs = sym.info.bounds.hi.membersBasedOnFlags(Flags.Method, Flags.Synthetic | Flags.Private)
.filterNot(_.symbol.owner.name.show == "Any")
.map { meth =>
DefImpl(
meth.symbol,
meth.symbol.name.show,
Nil,
path(meth.symbol),
returnType(meth.info),
typeParams(meth.symbol),
paramLists(meth.info),
implicitlyAddedFrom = Some(returnType(meth.symbol.owner.info))
)
}.toList

val vals = sym.info.fields.filterNot(_.symbol.is(Flags.Private | Flags.Synthetic)).map { value =>
ValImpl(
value.symbol,
value.symbol.name.show,
Nil, path(value.symbol),
returnType(value.info),
implicitlyAddedFrom = Some(returnType(value.symbol.owner.info))
)
}.toList

val vals = sym.info.fields.filterNot(_.symbol.is(Flags.Private | Flags.Synthetic)).map { value =>
ValImpl(
value.symbol,
value.symbol.name.show,
Nil, path(value.symbol),
returnType(value.info),
implicitlyAddedFrom = Some(returnType(value.symbol.owner.info))
)
}
}

defs ++ vals
defs ++ vals
}
else Nil
}


Expand Down
15 changes: 14 additions & 1 deletion doc-tool/src/dotty/tools/dottydoc/model/factories.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import dotc.core.TypeApplications._
import dotc.core.Contexts.Context
import dotc.core.Symbols.{ Symbol, ClassSymbol }
import dotty.tools.dotc.core.SymDenotations._
import dotty.tools.dotc.config.Printers.dottydoc
import dotty.tools.dotc.core.Names.TypeName
import dotc.ast.Trees._

Expand Down Expand Up @@ -105,6 +106,17 @@ object factories {
else paramName

typeRef(name)
case tr: TermRef =>
/** A `TermRef` appears in the return type in e.g:
* ```
* def id[T](t: T): t.type = t
* ```
*/
val name = tr.show
if (!name.endsWith(".type"))
ctx.warning(s"unhandled return type found: $tr")

typeRef(name, params = params)
}

expandTpe(t)
Expand Down Expand Up @@ -154,7 +166,8 @@ object factories {

case annot: AnnotatedType => paramLists(annot.tpe)
case (_: PolyParam | _: RefinedType | _: TypeRef | _: ThisType |
_: ExprType | _: OrType | _: AndType | _: HKApply) => Nil // return types should not be in the paramlist
_: ExprType | _: OrType | _: AndType | _: HKApply | _: TermRef) =>
Nil // return types should not be in the paramlist
}

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