@@ -11,8 +11,6 @@ import dotty.tools.scaladoc.cc.*
1111import NameNormalizer ._
1212import SyntheticsSupport ._
1313
14- private case class FunKind (isPure : Boolean , isImplicit : Boolean )
15-
1614trait TypesSupport :
1715 self : TastyParser =>
1816
@@ -142,9 +140,9 @@ trait TypesSupport:
142140 case t @ AppliedType (base, args) if t.isFunctionType =>
143141 functionType(base, args, skipThisTypePrefix)(using inCC = Some (refs))
144142 case t : Refinement if t.isFunctionType =>
145- inner(base, skipThisTypePrefix)(using inCC = Some (refs))
143+ inner(base, skipThisTypePrefix)(using indent = indent, skipTypeSuffix = skipTypeSuffix, inCC = Some (refs))
146144 case t if t.isCapSet => emitCaptureSet(refs, skipThisTypePrefix, omitCap = false )
147- case _ => inner(base, skipThisTypePrefix) ++ emitCapturing(refs, skipThisTypePrefix)
145+ case t => inner(base, skipThisTypePrefix) ++ emitCapturing(refs, skipThisTypePrefix)
148146 case AnnotatedType (tpe, _) =>
149147 inner(tpe, skipThisTypePrefix)
150148 case tl @ TypeLambda (params, paramBounds, AppliedType (tpe, args))
@@ -169,6 +167,8 @@ trait TypesSupport:
169167 inner(Refinement (at, " apply" , mt), skipThisTypePrefix)
170168
171169 case r : Refinement => { // (parent, name, info)
170+ val inCC0 = inCC
171+ given Option [List [TypeRepr ]] = None // do not propagate capture set beyond this point
172172 def getRefinementInformation (t : TypeRepr ): List [TypeRepr ] = t match {
173173 case r : Refinement => getRefinementInformation(r.parent) :+ r
174174 case t => List (t)
@@ -224,16 +224,16 @@ trait TypesSupport:
224224 val arrPrefix = if isCtx then " ?" else " "
225225 val arrow =
226226 if ccEnabled then
227- inCC match
227+ inCC0 match
228228 case None | Some (Nil ) => keyword(arrPrefix + " ->" ).l
229229 case Some (List (c)) if c.isCaptureRoot => keyword(arrPrefix + " =>" ).l
230230 case Some (refs) => keyword(arrPrefix + " ->" ) :: emitCaptureSet(refs, skipThisTypePrefix)
231231 else keyword(arrPrefix + " =>" ).l
232- val resType = inner(m.resType, skipThisTypePrefix)( using inCC = None )
232+ val resType = inner(m.resType, skipThisTypePrefix)
233233 paramList ++ (plain(" " ) :: arrow) ++ (plain(" " ) :: resType)
234234 else
235235 val sym = defn.FunctionClass (m.paramTypes.length, isCtx)
236- inner(sym.typeRef.appliedTo(m.paramTypes :+ m.resType), skipThisTypePrefix)( using inCC = None )
236+ inner(sym.typeRef.appliedTo(m.paramTypes :+ m.resType), skipThisTypePrefix)
237237 case other => noSupported(" Dependent function type without MethodType refinement" )
238238 }
239239
@@ -286,25 +286,27 @@ trait TypesSupport:
286286 case tp @ TypeRef (qual, typeName) =>
287287 qual match {
288288 case r : RecursiveThis => tpe(s " this. $typeName" ).l
289+ case t if skipPrefix(t, elideThis, originalOwner, skipThisTypePrefix) =>
290+ tpe(tp.typeSymbol)
291+ case _ : TermRef | _ : ParamRef =>
292+ val suffix = if tp.typeSymbol == Symbol .noSymbol then tpe(typeName).l else tpe(tp.typeSymbol)
293+ inner(qual, skipThisTypePrefix)(using skipTypeSuffix = true , inCC = inCC) ++ plain(" ." ).l ++ suffix
289294 case ThisType (tr) =>
290- val typeFromSupertypeConstructor = findSupertype(elideThis, tr.typeSymbol) match
295+ findSupertype(elideThis, tr.typeSymbol) match
291296 case Some ((sym, AppliedType (tr2, args))) =>
292297 sym.tree.asInstanceOf [ClassDef ].constructor.paramss.headOption match
293298 case Some (TypeParamClause (tpc)) =>
294299 tpc.zip(args).collectFirst {
295300 case (TypeDef (name, _), arg) if name == typeName => arg
296- }.map(inner(_, skipThisTypePrefix))
297- case _ => None
298- case _ => None
299- typeFromSupertypeConstructor.getOrElse:
300- if skipPrefix(qual, elideThis, originalOwner, skipThisTypePrefix) then
301- tpe(tp.typeSymbol)
302- else
303- val sig = inParens(inner(qual, skipThisTypePrefix)(using skipTypeSuffix = true ), shouldWrapInParens(qual, tp, true ))
301+ } match
302+ case Some (tr) => inner(tr, skipThisTypePrefix)
303+ case None => tpe(tp.typeSymbol)
304+ case _ => tpe(tp.typeSymbol)
305+ case Some (_) => tpe(tp.typeSymbol)
306+ case None =>
307+ val sig = inParens(inner(qual, skipThisTypePrefix)(using skipTypeSuffix = true , inCC = inCC), shouldWrapInParens(qual, tp, true ))
304308 sig ++ plain(" ." ).l ++ tpe(tp.typeSymbol)
305309
306- case t if skipPrefix(t, elideThis, originalOwner, skipThisTypePrefix) =>
307- tpe(tp.typeSymbol)
308310 case _ : TermRef | _ : ParamRef =>
309311 val suffix = if tp.typeSymbol == Symbol .noSymbol then tpe(typeName).l else tpe(tp.typeSymbol)
310312 inner(qual, skipThisTypePrefix)(using skipTypeSuffix = true ) ++ plain(" ." ).l ++ suffix
@@ -316,7 +318,7 @@ trait TypesSupport:
316318 case tr @ TermRef (qual, typeName) =>
317319 val prefix = qual match
318320 case t if skipPrefix(t, elideThis, originalOwner, skipThisTypePrefix) => Nil
319- case tp => inner(tp, skipThisTypePrefix)(using skipTypeSuffix = true ) ++ plain(" ." ).l
321+ case tp => inner(tp, skipThisTypePrefix)(using skipTypeSuffix = true , inCC = inCC ) ++ plain(" ." ).l
320322 val suffix = if skipTypeSuffix then Nil else List (plain(" ." ), keyword(" type" ))
321323 val typeSig = tr.termSymbol.tree match
322324 case vd : ValDef if tr.termSymbol.flags.is(Flags .Module ) =>
@@ -335,9 +337,9 @@ trait TypesSupport:
335337 val spaces = " " * (indent)
336338 val casesTexts = cases.flatMap {
337339 case MatchCase (from, to) =>
338- keyword(caseSpaces + " case " ).l ++ inner(from, skipThisTypePrefix) ++ keyword(" => " ).l ++ inner(to, skipThisTypePrefix)(using indent = indent + 2 ) ++ plain(" \n " ).l
340+ keyword(caseSpaces + " case " ).l ++ inner(from, skipThisTypePrefix) ++ keyword(" => " ).l ++ inner(to, skipThisTypePrefix)(using indent = indent + 2 , inCC = inCC ) ++ plain(" \n " ).l
339341 case TypeLambda (_, _, MatchCase (from, to)) =>
340- keyword(caseSpaces + " case " ).l ++ inner(from, skipThisTypePrefix) ++ keyword(" => " ).l ++ inner(to, skipThisTypePrefix)(using indent = indent + 2 ) ++ plain(" \n " ).l
342+ keyword(caseSpaces + " case " ).l ++ inner(from, skipThisTypePrefix) ++ keyword(" => " ).l ++ inner(to, skipThisTypePrefix)(using indent = indent + 2 , inCC = inCC ) ++ plain(" \n " ).l
341343 }
342344 inner(sc, skipThisTypePrefix) ++ keyword(" match " ).l ++ plain(" {\n " ).l ++ casesTexts ++ plain(spaces + " }" ).l
343345
@@ -371,7 +373,7 @@ trait TypesSupport:
371373 ): SSignature =
372374 import reflect ._
373375 val arrow = plain(" " ) :: (emitFunctionArrow(using q)(funTy, inCC, skipThisTypePrefix) ++ plain(" " ).l)
374- given Option [List [TypeRepr ]] = None // FIXME: this is ugly
376+ given Option [List [TypeRepr ]] = None // do not propagate capture set beyond this point
375377 args match
376378 case Nil => Nil
377379 case List (rtpe) => plain(" ()" ).l ++ arrow ++ inner(rtpe, skipThisTypePrefix)
@@ -403,14 +405,14 @@ trait TypesSupport:
403405 ) =
404406 import reflect ._
405407 def regularTypeBounds (low : TypeRepr , high : TypeRepr ) =
406- if low == high then keyword(" = " ).l ++ inner(low, skipThisTypePrefix)(using elideThis, originalOwner)
408+ if low == high then keyword(" = " ).l ++ inner(low, skipThisTypePrefix)(using elideThis, originalOwner, inCC = inCC )
407409 else typeBound(low, low = true , skipThisTypePrefix)(using elideThis, originalOwner) ++ typeBound(high, low = false , skipThisTypePrefix)(using elideThis, originalOwner)
408410 high.match
409411 case TypeLambda (params, paramBounds, resType) =>
410412 if resType.typeSymbol == defn.AnyClass then
411413 plain(" [" ).l ++ commas(params.zip(paramBounds).map { (name, typ) =>
412414 val normalizedName = if name.matches(" _\\ $\\ d*" ) then " _" else name
413- tpe(normalizedName)(using inCC).l ++ inner(typ, skipThisTypePrefix)(using elideThis, originalOwner)
415+ tpe(normalizedName)(using inCC).l ++ inner(typ, skipThisTypePrefix)(using elideThis, originalOwner, inCC = inCC )
414416 }) ++ plain(" ]" ).l
415417 else
416418 regularTypeBounds(low, high)
0 commit comments