Skip to content

Commit c885a7c

Browse files
committed
Encode HKT class type parameters (semi) correctly
1 parent d220fe3 commit c885a7c

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ object Inkuire {
7070
)
7171
)
7272
)
73+
74+
def StarProjection: Type =
75+
Type(
76+
name = TypeName("_"),
77+
itid = Some(ITID("_", isParsed = false)),
78+
isStarProjection = true
79+
)
7380
}
7481

7582
case class TypeName(name: String) {

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ trait InkuireSupport:
1818
private given qctx.type = qctx
1919

2020
private def paramsForClass(classDef: ClassDef, vars: Set[String]): Seq[Inkuire.Variance] =
21-
classDef.getTypeParams.map(mkTypeArgumentInkuire(_, vars))
21+
classDef.getTypeParams.map(mkTypeArgumentInkuire)
2222

2323
given TreeSyntaxInkuire: AnyRef with
2424
extension (tpeTree: Tree)
@@ -58,19 +58,28 @@ trait InkuireSupport:
5858
extension (tpe: TypeRepr)
5959
def asInkuire(vars: Set[String]): Inkuire.Type = inner(tpe, vars)
6060

61-
def mkTypeArgumentInkuire(argument: TypeDef, vars: Set[String] = Set.empty): Inkuire.Variance =
61+
def mkTypeArgumentInkuire(argument: TypeDef): Inkuire.Variance =
62+
//TODO [Inkuire] Type bounds (other than just HKTs)
6263
val name = argument.symbol.normalizedName
6364
val normalizedName = if name.matches("_\\$\\d*") then "_" else name
65+
val params = 1.to(typeVariableDeclarationParamsNo(argument)).map(_ => Inkuire.Type.StarProjection)
6466
val t = Inkuire.Type(
6567
name = Inkuire.TypeName(normalizedName),
6668
itid = argument.symbol.itid,
6769
isVariable = true,
68-
params = Seq.empty //TODO [Inkuire] Type Lambdas
70+
params = params.map(Inkuire.Invariance(_))
6971
)
7072
if argument.symbol.flags.is(Flags.Covariant) then Inkuire.Covariance(t)
7173
else if argument.symbol.flags.is(Flags.Contravariant) then Inkuire.Contravariance(t)
7274
else Inkuire.Invariance(t)
7375

76+
def typeVariableDeclarationParamsNo(argument: TypeDef): Int =
77+
argument.rhs match
78+
case t: TypeTree => t.tpe match
79+
case TypeBounds(_, TypeLambda(names, _, _)) => names.size
80+
case _ => 0
81+
case _ => 0
82+
7483
private def isRepeatedAnnotation(term: Term) =
7584
term.tpe match
7685
case t: TypeRef => t.name == "Repeated" && t.qualifier.match

0 commit comments

Comments
 (0)