Skip to content

Commit d44a189

Browse files
Merge pull request #14565 from dotty-staging/scaladoc/tuple-type-fix
Scaladoc: Add necessary parentheses in function types
2 parents 0b3dd14 + 227cd6e commit d44a189

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package tests.functionTypeSignatures
2+
3+
type A = ((Int, Int)) => Int
4+
5+
type B = (Int | String) => Int
6+
7+
type C = (Int & String) => Int
8+
9+
type E = (A => B) => B
10+

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,11 @@ trait TypesSupport:
199199
case Seq(rtpe) =>
200200
plain("()").l ++ keyword(arrow).l ++ inner(rtpe)
201201
case Seq(arg, rtpe) =>
202+
def withParentheses(tpe: TypeRepr) = plain("(").l ++ inner(tpe) ++ plain(")").l
202203
val partOfSignature = arg match
203-
case byName: ByNameType => plain("(").l ++ inner(byName) ++ plain(")").l
204-
case _ => inner(arg)
204+
case tpe @ (_:TermRef | _:TypeRef | _:ConstantType | _: ParamRef) => inner(arg)
205+
case tpe: AppliedType if !tpe.isFunctionType && !tpe.isTupleN => inner(arg)
206+
case _ => withParentheses(arg)
205207
partOfSignature ++ keyword(arrow).l ++ inner(rtpe)
206208
case args =>
207209
plain("(").l ++ commas(args.init.map(inner)) ++ plain(")").l ++ keyword(arrow).l ++ inner(args.last)

scaladoc/test/dotty/tools/scaladoc/signatures/TranslatableSignaturesTestCases.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,5 @@ class Exports extends SignatureTest("exports2", SignatureTest.all, sourceFiles =
9494
class ContextFunctions extends SignatureTest("contextfunctions", SignatureTest.all)
9595

9696
class MarkdownCode extends SignatureTest("markdowncode", SignatureTest.all)
97+
98+
class FunctionTypeSignatures extends SignatureTest("functionTypeSignatures", SignatureTest.all)

0 commit comments

Comments
 (0)