@@ -21,12 +21,13 @@ trait TypesSupport:
21
21
def asSignature (elideThis : reflect.ClassDef , originalOwner : reflect.Symbol , skipThisTypePrefix : Boolean ): SSignature =
22
22
import reflect ._
23
23
tpeTree match
24
- case TypeBoundsTree (low, high) => typeBoundsTreeOfHigherKindedType(low.tpe, high.tpe, skipThisTypePrefix)(using elideThis, originalOwner)
24
+ case TypeBoundsTree (low, high) => typeBoundsTreeOfHigherKindedType(low.tpe, high.tpe, skipThisTypePrefix)(using elideThis, originalOwner, inCC = None )
25
25
case tpeTree : TypeTree => topLevelProcess(tpeTree.tpe, skipThisTypePrefix)(using elideThis, originalOwner)
26
26
case term : Term => topLevelProcess(term.tpe, skipThisTypePrefix)(using elideThis, originalOwner)
27
27
def asSignature (elideThis : reflect.ClassDef , originalOwner : reflect.Symbol ): SSignature =
28
28
tpeTree.asSignature(elideThis, originalOwner, skipThisTypePrefix = false )
29
29
30
+
30
31
given TypeSyntax : AnyRef with
31
32
extension (using Quotes )(tpe : reflect.TypeRepr )
32
33
def asSignature (elideThis : reflect.ClassDef , originalOwner : reflect.Symbol , skipThisTypePrefix : Boolean ): SSignature =
@@ -39,19 +40,30 @@ trait TypesSupport:
39
40
40
41
private def keyword (str : String ): SignaturePart = Keyword (str)
41
42
42
- private def tpe (str : String , dri : DRI ): SignaturePart = dotty.tools.scaladoc.Type (str, Some (dri))
43
+ private def tpe (str : String , dri : DRI )(using inCC : Option [Unit ]): SignaturePart =
44
+ if inCC.isDefined then
45
+ dotty.tools.scaladoc.Plain (str)
46
+ else
47
+ dotty.tools.scaladoc.Type (str, Some (dri))
43
48
44
- private def tpe (str : String ): SignaturePart = dotty.tools.scaladoc.Type (str, None )
49
+ private def tpe (str : String )(using inCC : Option [Unit ]): SignaturePart =
50
+ if inCC.isDefined then
51
+ dotty.tools.scaladoc.Plain (str)
52
+ else
53
+ dotty.tools.scaladoc.Type (str, None )
45
54
46
55
protected def inParens (s : SSignature , wrap : Boolean = true ) =
47
56
if wrap then plain(" (" ).l ++ s ++ plain(" )" ).l else s
48
57
49
58
extension (on : SignaturePart ) def l : List [SignaturePart ] = List (on)
50
59
51
- private def tpe (using Quotes )(symbol : reflect.Symbol ): SSignature =
60
+ private def tpe (using Quotes )(symbol : reflect.Symbol )( using inCC : Option [ Unit ]) : SSignature =
52
61
import SymOps ._
53
62
val dri : Option [DRI ] = Option (symbol).filterNot(_.isHiddenByVisibility).map(_.dri)
54
- dotty.tools.scaladoc.Type (symbol.normalizedName, dri).l
63
+ if inCC.isDefined then
64
+ dotty.tools.scaladoc.Plain (symbol.normalizedName).l
65
+ else
66
+ dotty.tools.scaladoc.Type (symbol.normalizedName, dri).l
55
67
56
68
private def commas (lists : List [SSignature ]) = lists match
57
69
case List (single) => single
@@ -93,6 +105,9 @@ trait TypesSupport:
93
105
originalOwner : reflect.Symbol ,
94
106
indent : Int = 0 ,
95
107
skipTypeSuffix : Boolean = false ,
108
+ // inCC means in capture-checking context.
109
+ // Somewhat hacky, because it should be a Boolean, but then it'd clash with skipTypeSuffix
110
+ inCC : Option [Unit ] = None ,
96
111
): SSignature =
97
112
import reflect ._
98
113
def noSupported (name : String ): SSignature =
@@ -108,7 +123,7 @@ trait TypesSupport:
108
123
++ keyword(" & " ).l
109
124
++ inParens(inner(right, skipThisTypePrefix), shouldWrapInParens(right, tp, false ))
110
125
case CapturingType (base, refs) =>
111
- inner(base, skipThisTypePrefix) ++ renderCaptureSet (refs)
126
+ inner(base, skipThisTypePrefix) ++ renderCapturing (refs)
112
127
case ByNameType (CapturingType (tpe, refs)) =>
113
128
refs match
114
129
case Nil => keyword(" -> " ) :: inner(tpe, skipThisTypePrefix)
@@ -355,7 +370,7 @@ trait TypesSupport:
355
370
}
356
371
357
372
private def typeBoundsTreeOfHigherKindedType (using Quotes )(low : reflect.TypeRepr , high : reflect.TypeRepr , skipThisTypePrefix : Boolean )(
358
- using elideThis : reflect.ClassDef , originalOwner : reflect.Symbol
373
+ using elideThis : reflect.ClassDef , originalOwner : reflect.Symbol , inCC : Option [ Unit ]
359
374
) =
360
375
import reflect ._
361
376
def regularTypeBounds (low : TypeRepr , high : TypeRepr ) =
@@ -366,7 +381,7 @@ trait TypesSupport:
366
381
if resType.typeSymbol == defn.AnyClass then
367
382
plain(" [" ).l ++ commas(params.zip(paramBounds).map { (name, typ) =>
368
383
val normalizedName = if name.matches(" _\\ $\\ d*" ) then " _" else name
369
- tpe(normalizedName).l ++ inner(typ, skipThisTypePrefix)(using elideThis, originalOwner)
384
+ tpe(normalizedName)( using inCC) .l ++ inner(typ, skipThisTypePrefix)(using elideThis, originalOwner)
370
385
}) ++ plain(" ]" ).l
371
386
else
372
387
regularTypeBounds(low, high)
@@ -448,3 +463,26 @@ trait TypesSupport:
448
463
tr match
449
464
case AnnotatedType (tr, _) => stripAnnotated(tr)
450
465
case other => other
466
+
467
+ private def renderCapability (using Quotes )(ref : reflect.TypeRepr )(using elideThis : reflect.ClassDef ): List [SignaturePart ] =
468
+ import reflect ._
469
+ ref match
470
+ case ReachCapability (c) => renderCapability(c) :+ Keyword (" *" )
471
+ case ThisType (_) => List (Keyword (" this" ))
472
+ case t => inner(t)(using skipTypeSuffix = true , inCC = Some (()))
473
+
474
+ private def renderCaptureSet (using Quotes )(refs : List [reflect.TypeRepr ])(using elideThis : reflect.ClassDef ): List [SignaturePart ] =
475
+ import dotty .tools .scaladoc .tasty .NameNormalizer ._
476
+ import reflect ._
477
+ refs match
478
+ case List (ref) if ref.isCaptureRoot => Nil
479
+ case refs =>
480
+ val res0 = refs.map(renderCapability)
481
+ val res1 = res0 match
482
+ case Nil => Nil
483
+ case other => other.reduce((r, e) => r ++ (List (Plain (" , " )) ++ e))
484
+ Plain (" {" ) :: (res1 ++ List (Plain (" }" )))
485
+
486
+ private def renderCapturing (using Quotes )(refs : List [reflect.TypeRepr ])(using elideThis : reflect.ClassDef ): List [SignaturePart ] =
487
+ import reflect ._
488
+ Keyword (" ^" ) :: renderCaptureSet(refs)
0 commit comments