Skip to content
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

Scaladoc: Add necessary parentheses in function types #14565

Merged
merged 2 commits into from Feb 25, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions scaladoc-testcases/src/tests/functionTypeSignatures.scala
@@ -0,0 +1,10 @@
package tests.functionTypeSignatures

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

type B = (Int | String) => Int
KacperFKorban marked this conversation as resolved.
Show resolved Hide resolved

type C = (Int & String) => Int

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

6 changes: 4 additions & 2 deletions scaladoc/src/dotty/tools/scaladoc/tasty/TypesSupport.scala
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
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)