Skip to content

Commit

Permalink
Merge pull request #14565 from dotty-staging/scaladoc/tuple-type-fix
Browse files Browse the repository at this point in the history
Scaladoc: Add necessary parentheses in function types
  • Loading branch information
KacperFKorban authored Feb 25, 2022
2 parents 0b3dd14 + 227cd6e commit d44a189
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
10 changes: 10 additions & 0 deletions scaladoc-testcases/src/tests/functionTypeSignatures.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package tests.functionTypeSignatures

type A = ((Int, Int)) => Int

type B = (Int | String) => Int

type C = (Int & String) => Int

type E = (A => B) => B

6 changes: 4 additions & 2 deletions scaladoc/src/dotty/tools/scaladoc/tasty/TypesSupport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,11 @@ trait TypesSupport:
case Seq(rtpe) =>
plain("()").l ++ keyword(arrow).l ++ inner(rtpe)
case Seq(arg, rtpe) =>
def withParentheses(tpe: TypeRepr) = plain("(").l ++ inner(tpe) ++ plain(")").l
val partOfSignature = arg match
case byName: ByNameType => plain("(").l ++ inner(byName) ++ plain(")").l
case _ => inner(arg)
case tpe @ (_:TermRef | _:TypeRef | _:ConstantType | _: ParamRef) => inner(arg)
case tpe: AppliedType if !tpe.isFunctionType && !tpe.isTupleN => inner(arg)
case _ => withParentheses(arg)
partOfSignature ++ keyword(arrow).l ++ inner(rtpe)
case args =>
plain("(").l ++ commas(args.init.map(inner)) ++ plain(")").l ++ keyword(arrow).l ++ inner(args.last)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,5 @@ class Exports extends SignatureTest("exports2", SignatureTest.all, sourceFiles =
class ContextFunctions extends SignatureTest("contextfunctions", SignatureTest.all)

class MarkdownCode extends SignatureTest("markdowncode", SignatureTest.all)

class FunctionTypeSignatures extends SignatureTest("functionTypeSignatures", SignatureTest.all)

0 comments on commit d44a189

Please sign in to comment.