Skip to content

Scaladoc: Fix rendering dependent function types #14327

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 3 commits into from
Feb 15, 2022
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
4 changes: 4 additions & 0 deletions scaladoc-testcases/src/tests/typesSignatures.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class Base
type H = () => String

type I = (Int, String, Int) => (String, Int)

type J = (a: A) => a.type

type K = [A] => (a: A) => a.type
}

class Operators
Expand Down
18 changes: 14 additions & 4 deletions scaladoc/src/dotty/tools/scaladoc/tasty/TypesSupport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ trait TypesSupport:
def noSupported(name: String): SSignature =
println(s"WARN: Unsupported type: $name: ${tp.show}")
plain(s"Unsupported[$name]").l

tp match
case OrType(left, right) => inner(left) ++ keyword(" | ").l ++ inner(right)
case AndType(left, right) => inner(left) ++ keyword(" & ").l ++ inner(right)
Expand All @@ -117,7 +116,6 @@ trait TypesSupport:
++ keyword(" =>> ").l
++ inner(resType)


case r: Refinement => { //(parent, name, info)
def getRefinementInformation(t: TypeRepr): List[TypeRepr] = t match {
case r: Refinement => getRefinementInformation(r.parent) :+ r
Expand Down Expand Up @@ -163,13 +161,25 @@ trait TypesSupport:
plain("[").l ++ paramBounds ++ plain("]").l ++ keyword(" => ").l ++ paramList ++ keyword(" => ").l ++ resType
case other => noSupported(s"Not supported type in refinement $info")
}

def parseDependentFunctionType(info: TypeRepr): SSignature = info match {
case m: MethodType =>
val paramList = getParamList(m)
paramList ++ keyword(" => ").l ++ inner(m.resType)
case other => noSupported("Dependent function type without MethodType refinement")
}

val refinementInfo = getRefinementInformation(r)
val refinedType = refinementInfo.head
val refinedElems = refinementInfo.tail.collect{ case r: Refinement => r }.toList
val prefix = if refinedType.typeSymbol != defn.ObjectClass then inner(refinedType) ++ plain(" ").l else Nil
if (refinedType.typeSymbol.fullName == "scala.PolyFunction" && refinedElems.size == 1) {
parsePolyFunction(refinedElems.head.info)
} else {
}
else if (r.isDependentFunctionType) {
parseDependentFunctionType(r.info)
}
else {
prefix ++ plain("{ ").l ++ refinedElems.flatMap(e => parseRefinedElem(e.name, e.info)) ++ plain(" }").l
}
}
Expand Down Expand Up @@ -274,7 +284,7 @@ trait TypesSupport:

case ParamRef(TypeLambda(names, _, _), i) => tpe(names.apply(i)).l

case ParamRef(m: MethodType, i) => tpe(m.paramNames(i)).l
case ParamRef(m: MethodType, i) => tpe(m.paramNames(i)).l ++ plain(".type").l

case RecursiveType(tp) => inner(tp)

Expand Down