From 60aba096c09455fe306f1dfb58a660bd9f6ea7e0 Mon Sep 17 00:00:00 2001 From: Kacper Korban Date: Fri, 28 Jan 2022 00:56:25 +0100 Subject: [PATCH] Correctly handle context functions in scaladoc closes #14343 --- scaladoc-testcases/src/tests/contextfunctions.scala | 4 ++++ scaladoc/src/dotty/tools/scaladoc/tasty/TypesSupport.scala | 7 ++++--- .../signatures/TranslatableSignaturesTestCases.scala | 2 ++ 3 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 scaladoc-testcases/src/tests/contextfunctions.scala diff --git a/scaladoc-testcases/src/tests/contextfunctions.scala b/scaladoc-testcases/src/tests/contextfunctions.scala new file mode 100644 index 000000000000..527053943b5e --- /dev/null +++ b/scaladoc-testcases/src/tests/contextfunctions.scala @@ -0,0 +1,4 @@ +package tests.contextfunctions + +val x: Int ?=> Float + = 5.0f diff --git a/scaladoc/src/dotty/tools/scaladoc/tasty/TypesSupport.scala b/scaladoc/src/dotty/tools/scaladoc/tasty/TypesSupport.scala index faa8b61f807f..c0197b152a5f 100644 --- a/scaladoc/src/dotty/tools/scaladoc/tasty/TypesSupport.scala +++ b/scaladoc/src/dotty/tools/scaladoc/tasty/TypesSupport.scala @@ -182,18 +182,19 @@ trait TypesSupport: ++ plain(" ").l ++ inner(typeList.last) else if t.isFunctionType then + val arrow = if t.isContextFunctionType then " ?=> " else " => " typeList match case Nil => Nil case Seq(rtpe) => - plain("()").l ++ keyword(" => ").l ++ inner(rtpe) + plain("()").l ++ keyword(arrow).l ++ inner(rtpe) case Seq(arg, rtpe) => val partOfSignature = arg match case byName: ByNameType => plain("(").l ++ inner(byName) ++ plain(")").l case _ => inner(arg) - partOfSignature ++ keyword(" => ").l ++ inner(rtpe) + partOfSignature ++ keyword(arrow).l ++ inner(rtpe) case args => - plain("(").l ++ commas(args.init.map(inner)) ++ plain(")").l ++ keyword(" => ").l ++ inner(args.last) + plain("(").l ++ commas(args.init.map(inner)) ++ plain(")").l ++ keyword(arrow).l ++ inner(args.last) else if t.isTupleN then typeList match case Nil => diff --git a/scaladoc/test/dotty/tools/scaladoc/signatures/TranslatableSignaturesTestCases.scala b/scaladoc/test/dotty/tools/scaladoc/signatures/TranslatableSignaturesTestCases.scala index d85d2d960d2c..e56b741f5fee 100644 --- a/scaladoc/test/dotty/tools/scaladoc/signatures/TranslatableSignaturesTestCases.scala +++ b/scaladoc/test/dotty/tools/scaladoc/signatures/TranslatableSignaturesTestCases.scala @@ -90,3 +90,5 @@ class ContextBounds extends SignatureTest("contextBounds", SignatureTest.all) class FBoundedTypeParameters extends SignatureTest("fboundedTypeParameters", SignatureTest.all) class Exports extends SignatureTest("exports2", SignatureTest.all, sourceFiles = List("exports1", "exports2")) + +class ContextFunctions extends SignatureTest("contextfunctions", SignatureTest.all)