Skip to content

Commit 97a27ef

Browse files
KacperFKorbantanishiking
authored andcommitted
Add currying signatures
1 parent 59fc594 commit 97a27ef

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

scaladoc-testcases/src/tests/inkuire.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,8 @@ class JustAClass {
1313
class JustAnotherClass extends JustAClass {
1414
def method(i: InType2): OutType2 = ???
1515
}
16+
17+
object InkuireObject {
18+
def function(i: InType1): OutType1 = ???
19+
val value: InType1 => OutType1 = ???
20+
}

scaladoc/src/dotty/tools/scaladoc/Inkuire.scala

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package dotty.tools.scaladoc
22

33
import dotty.tools.scaladoc.util._
4-
import scala.collection.mutable.{ Map => MMap}
54

65
object Inkuire {
76

@@ -20,6 +19,18 @@ object Inkuire {
2019
jsonObject(("inkuirePaths", jsonList(paths))).toString
2120
}
2221

22+
def curry(e: Signature): Signature = {
23+
e.result.typ match
24+
case t: Type if t.name.name == s"Function${t.params.size-1}" =>
25+
curry(
26+
e.copy(
27+
arguments = e.arguments ++ t.params.init.map(_.typ).map(Contravariance(_)),
28+
result = Covariance(t.params.last.typ)
29+
)
30+
)
31+
case _ => e
32+
}
33+
2334
case class InkuireDb(
2435
functions: Seq[ExternalSignature],
2536
types: Map[ITID, (Type, Seq[Type])],

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ trait ClassLikeSupport:
190190
uri = methodSymbol.dri.externalLink.getOrElse(""),
191191
entryType = "def"
192192
)
193-
Inkuire.db = Inkuire.db.copy(functions = Inkuire.db.functions :+ sgn)
193+
val curriedSgn = sgn.copy(signature = Inkuire.curry(sgn.signature))
194+
Inkuire.db = Inkuire.db.copy(functions = Inkuire.db.functions :+ curriedSgn)
194195
}
195196

196197
classDef.symbol.declaredFields
@@ -216,7 +217,8 @@ trait ClassLikeSupport:
216217
uri = valSymbol.dri.externalLink.getOrElse(""),
217218
entryType = "val"
218219
)
219-
Inkuire.db = Inkuire.db.copy(functions = Inkuire.db.functions :+ sgn)
220+
val curriedSgn = sgn.copy(signature = Inkuire.curry(sgn.signature))
221+
Inkuire.db = Inkuire.db.copy(functions = Inkuire.db.functions :+ curriedSgn)
220222
}
221223
}
222224

0 commit comments

Comments
 (0)