@@ -174,17 +174,17 @@ class PlainPrinter(_ctx: Context) extends Printer {
174174 // ~ Str("?").provided(!cs.isConst)
175175 core ~ cs.optionalInfo
176176
177- private def toTextRetainedElem [ T <: Untyped ] (ref : Tree [ T ] ): Text = ref match
178- case ref : RefTree [ ? ] =>
179- ref.typeOpt match
180- case c : Capability => toTextCapability(c )
181- case _ => toText(ref)
182- case _ => toText(ref)
183-
184- private def toTextRetainedElems [ T <: Untyped ] (refs : List [Tree [ T ] ]): Text =
177+ private def toTextRetainedElem (ref : Type ): Text = ref match
178+ case c : Capability => toTextCapability(c)
179+ case _ =>
180+ try toTextCapability(ref.toCapability )
181+ catch case _ =>
182+ toText(ref)
183+
184+ private def toTextRetainedElems (refs : List [Type ]): Text =
185185 " {" ~ Text (refs.map(ref => toTextRetainedElem(ref)), " , " ) ~ " }"
186186
187- type GeneralCaptureSet = CaptureSet | List [tpd. Tree ]
187+ type GeneralCaptureSet = CaptureSet | List [Type ]
188188
189189 protected def isUniversalCaptureSet (refs : GeneralCaptureSet ): Boolean = refs match
190190 case refs : CaptureSet =>
@@ -203,12 +203,12 @@ class PlainPrinter(_ctx: Context) extends Printer {
203203 )
204204 isUniversal
205205 || ! refs.elems.isEmpty && refs.elems.forall(_.isCapOrFresh) && ! ccVerbose
206- case (ref : tpd. Tree ) :: Nil => ref.symbol == defn.captureRoot
206+ case (ref : TermRef ) :: Nil => ref.symbol == defn.captureRoot
207207 case _ => false
208208
209209 protected def toTextGeneralCaptureSet (refs : GeneralCaptureSet ): Text = refs match
210210 case refs : CaptureSet => toTextCaptureSet(refs)
211- case refs : List [tpd. Tree ] => toTextRetainedElems(refs)
211+ case refs : List [Type ] => toTextRetainedElems(refs)
212212
213213 /** Print capturing type, overridden in RefinedPrinter to account for
214214 * capturing function types.
@@ -284,10 +284,9 @@ class PlainPrinter(_ctx: Context) extends Printer {
284284 && refs.isReadOnly
285285 then toText(parent)
286286 else toTextCapturing(parent, refs, boxText)
287- case tp @ RetainingType (parent, refsType) =>
288- val refs = refsType.retainedElementsRaw
287+ case tp @ RetainingType (parent, refSet) =>
289288 if Feature .ccEnabledSomewhere then
290- toTextCapturing(parent, refs.map(r => ast.tpd. TypeTree (r)) , " " ) ~ Str (" R" ).provided(printDebug)
289+ toTextCapturing(parent, refSet.retainedElementsRaw , " " ) ~ Str (" R" ).provided(printDebug)
291290 else toText(parent)
292291 case tp : PreviousErrorType if ctx.settings.XprintTypes .value =>
293292 " <error>" // do not print previously reported error message because they may try to print this error type again recursively
@@ -314,7 +313,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
314313 case AnnotatedType (parent, ann) if ann.symbol == defn.RetainsByNameAnnot =>
315314 ann.tree.retainedSet.retainedElementsRaw match
316315 case (ref : TermRef ) :: Nil if ref.symbol == defn.captureRoot => Str (" =>" )
317- case refs => Str (" ->" ) ~ toTextRetainedElems(refs.map(r => ast.tpd. TypeTree (r)) )
316+ case refs => Str (" ->" ) ~ toTextRetainedElems(refs)
318317 case _ =>
319318 if Feature .pureFunsEnabled then " ->" else " =>"
320319 changePrec(GlobalPrec )(arrowText ~ " " ~ toText(restp))
0 commit comments