Skip to content

Commit a98abb5

Browse files
authored
Merge pull request #14327 from Sporarum/scaladoc-dependent-type
Scaladoc: Fix rendering dependent function types
2 parents 37e997a + f2888c4 commit a98abb5

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

scaladoc-testcases/src/tests/typesSignatures.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ class Base
3535
type H = () => String
3636

3737
type I = (Int, String, Int) => (String, Int)
38+
39+
type J = (a: A) => a.type
40+
41+
type K = [A] => (a: A) => a.type
3842
}
3943

4044
class Operators

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ trait TypesSupport:
9292
def noSupported(name: String): SSignature =
9393
println(s"WARN: Unsupported type: $name: ${tp.show}")
9494
plain(s"Unsupported[$name]").l
95-
9695
tp match
9796
case OrType(left, right) => inner(left) ++ keyword(" | ").l ++ inner(right)
9897
case AndType(left, right) => inner(left) ++ keyword(" & ").l ++ inner(right)
@@ -117,7 +116,6 @@ trait TypesSupport:
117116
++ keyword(" =>> ").l
118117
++ inner(resType)
119118

120-
121119
case r: Refinement => { //(parent, name, info)
122120
def getRefinementInformation(t: TypeRepr): List[TypeRepr] = t match {
123121
case r: Refinement => getRefinementInformation(r.parent) :+ r
@@ -163,13 +161,25 @@ trait TypesSupport:
163161
plain("[").l ++ paramBounds ++ plain("]").l ++ keyword(" => ").l ++ paramList ++ keyword(" => ").l ++ resType
164162
case other => noSupported(s"Not supported type in refinement $info")
165163
}
164+
165+
def parseDependentFunctionType(info: TypeRepr): SSignature = info match {
166+
case m: MethodType =>
167+
val paramList = getParamList(m)
168+
paramList ++ keyword(" => ").l ++ inner(m.resType)
169+
case other => noSupported("Dependent function type without MethodType refinement")
170+
}
171+
166172
val refinementInfo = getRefinementInformation(r)
167173
val refinedType = refinementInfo.head
168174
val refinedElems = refinementInfo.tail.collect{ case r: Refinement => r }.toList
169175
val prefix = if refinedType.typeSymbol != defn.ObjectClass then inner(refinedType) ++ plain(" ").l else Nil
170176
if (refinedType.typeSymbol.fullName == "scala.PolyFunction" && refinedElems.size == 1) {
171177
parsePolyFunction(refinedElems.head.info)
172-
} else {
178+
}
179+
else if (r.isDependentFunctionType) {
180+
parseDependentFunctionType(r.info)
181+
}
182+
else {
173183
prefix ++ plain("{ ").l ++ refinedElems.flatMap(e => parseRefinedElem(e.name, e.info)) ++ plain(" }").l
174184
}
175185
}
@@ -274,7 +284,7 @@ trait TypesSupport:
274284

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

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

279289
case RecursiveType(tp) => inner(tp)
280290

0 commit comments

Comments
 (0)