@@ -101,7 +101,12 @@ trait TypesSupport:
101101 case ByNameType (tpe) => keyword(" => " ) :: inner(tpe)
102102 case ConstantType (constant) =>
103103 plain(constant.show).l
104- case ThisType (tpe) => inner(tpe)
104+ case ThisType (tpe) =>
105+ val prefix = findSupertype(elideThis, tpe.typeSymbol) match
106+ case Some (_) => Nil
107+ case None => inner(tpe) ++ plain(" ." ).l
108+ val suffix = if skipTypeSuffix then Nil else List (plain(" ." ), keyword(" type" ))
109+ prefix ++ keyword(" this" ).l ++ suffix
105110 case AnnotatedType (AppliedType (_, Seq (tpe)), annotation) if isRepeatedAnnotation(annotation) =>
106111 inner(tpe) :+ plain(" *" )
107112 case AppliedType (repeatedClass, Seq (tpe)) if isRepeated(repeatedClass) =>
@@ -220,10 +225,6 @@ trait TypesSupport:
220225 }) ++ plain(" ]" ).l
221226
222227 case tp @ TypeRef (qual, typeName) =>
223- def defaultSignature () =
224- val suffix = keyword(" #" ).l ++ tpe(tp.typeSymbol)
225- inParens(inner(qual), shouldWrapInParens(qual, tp, true )) ++ suffix
226-
227228 qual match {
228229 case r : RecursiveThis => tpe(s " this. $typeName" ).l
229230 case t if skipPrefix(t, elideThis) =>
@@ -232,21 +233,23 @@ trait TypesSupport:
232233 val suffix = if tp.typeSymbol == Symbol .noSymbol then tpe(typeName).l else tpe(tp.typeSymbol)
233234 inner(qual)(using skipTypeSuffix = true ) ++ plain(" ." ).l ++ suffix
234235 case ThisType (tr) =>
235- import dotty .tools .scaladoc .tasty .SymOps .isHiddenByVisibility
236-
237- val supertype = getSupertypes(elideThis).filterNot((s, t) => s.isHiddenByVisibility).find((s, t) => s == tr.typeSymbol)
238- supertype match
236+ findSupertype(elideThis, tr.typeSymbol) match
239237 case Some ((sym, AppliedType (tr2, args))) =>
240238 sym.tree.asInstanceOf [ClassDef ].constructor.paramss.headOption match
241239 case Some (TypeParamClause (tpc)) =>
242240 tpc.zip(args).collectFirst {
243241 case (TypeDef (name, _), arg) if name == typeName => arg
244242 } match
245243 case Some (tr) => inner(tr)
246- case _ => defaultSignature()
247- case _ => defaultSignature()
248- case _ => defaultSignature()
249- case _ => defaultSignature()
244+ case None => tpe(tp.typeSymbol)
245+ case _ => tpe(tp.typeSymbol)
246+ case Some (_) => tpe(tp.typeSymbol)
247+ case None =>
248+ val sig = inParens(inner(qual)(using skipTypeSuffix = true ), shouldWrapInParens(qual, tp, true ))
249+ sig ++ plain(" ." ).l ++ tpe(tp.typeSymbol)
250+ case _ =>
251+ val sig = inParens(inner(qual), shouldWrapInParens(qual, tp, true ))
252+ sig ++ keyword(" #" ).l ++ tpe(tp.typeSymbol)
250253 }
251254
252255 case tr @ TermRef (qual, typeName) =>
@@ -326,6 +329,9 @@ trait TypesSupport:
326329 regularTypeBounds(low, high)
327330 case _ => regularTypeBounds(low, high)
328331
332+ private def findSupertype (using Quotes )(c : reflect.ClassDef , sym : reflect.Symbol ) =
333+ getSupertypes(c).find((s, t) => s == sym)
334+
329335 private def skipPrefix (using Quotes )(tr : reflect.TypeRepr , elideThis : reflect.ClassDef ) =
330336 import reflect ._
331337
0 commit comments