@@ -144,44 +144,49 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
144144 private def arrow (isGiven : Boolean , isPure : Boolean ): String =
145145 (if isGiven then " ?" else " " ) + (if isPure then " ->" else " =>" )
146146
147- override def toText (tp : Type ): Text = controlled {
148- def toTextTuple (args : List [Type ]): Text =
149- " (" ~ argsText(args) ~ " )"
147+ private def toTextFunction (tp : AppliedType , refs : Text = Str (" " )): Text =
148+ val AppliedType (tycon, args) = (tp : @ unchecked)
149+ val tsym = tycon.typeSymbol
150+ val isGiven = tsym.name.isContextFunction
151+ val isPure = Feature .pureFunsEnabled && ! tsym.name.isImpureFunction
152+ changePrec(GlobalPrec ) {
153+ val argStr : Text =
154+ if args.length == 2
155+ && ! defn.isTupleNType(args.head)
156+ && ! isGiven
157+ then
158+ atPrec(InfixPrec ) { argText(args.head) }
159+ else
160+ " ("
161+ ~ argsText(args.init)
162+ ~ " )"
163+ argStr ~ " " ~ arrow(isGiven, isPure) ~ refs ~ " " ~ argText(args.last)
164+ }
150165
151- def toTextFunction (args : List [Type ], isGiven : Boolean , isPure : Boolean ): Text =
166+ private def toTextMethodAsFunction (info : Type , isPure : Boolean , refs : Text = Str (" " )): Text = info match
167+ case info : MethodType =>
152168 changePrec(GlobalPrec ) {
153- val argStr : Text =
154- if args.length == 2
155- && ! defn.isTupleNType(args.head)
156- && ! isGiven
157- then
158- atPrec(InfixPrec ) { argText(args.head) }
159- else
160- " ("
161- ~ argsText(args.init)
162- ~ " )"
163- argStr ~ " " ~ arrow(isGiven, isPure) ~ " " ~ argText(args.last)
169+ " ("
170+ ~ paramsText(info)
171+ ~ " ) "
172+ ~ arrow(info.isImplicitMethod, isPure)
173+ ~ refs
174+ ~ " "
175+ ~ toTextMethodAsFunction(info.resultType, isPure)
176+ }
177+ case info : PolyType =>
178+ changePrec(GlobalPrec ) {
179+ " ["
180+ ~ paramsText(info)
181+ ~ " ] => "
182+ ~ toTextMethodAsFunction(info.resultType, isPure)
164183 }
184+ case _ =>
185+ toText(info)
165186
166- def toTextMethodAsFunction (info : Type , isPure : Boolean ): Text = info match
167- case info : MethodType =>
168- changePrec(GlobalPrec ) {
169- " ("
170- ~ paramsText(info)
171- ~ " ) "
172- ~ arrow(info.isImplicitMethod, isPure)
173- ~ " "
174- ~ toTextMethodAsFunction(info.resultType, isPure)
175- }
176- case info : PolyType =>
177- changePrec(GlobalPrec ) {
178- " ["
179- ~ paramsText(info)
180- ~ " ] => "
181- ~ toTextMethodAsFunction(info.resultType, isPure)
182- }
183- case _ =>
184- toText(info)
187+ override def toText (tp : Type ): Text = controlled {
188+ def toTextTuple (args : List [Type ]): Text =
189+ " (" ~ argsText(args) ~ " )"
185190
186191 def isInfixType (tp : Type ): Boolean = tp match
187192 case AppliedType (tycon, args) =>
@@ -223,9 +228,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
223228 val tsym = tycon.typeSymbol
224229 if tycon.isRepeatedParam then toTextLocal(args.head) ~ " *"
225230 else if tp.isConvertibleParam then " into " ~ toText(args.head)
226- else if defn.isFunctionSymbol(tsym) then
227- toTextFunction(args, tsym.name.isContextFunction,
228- isPure = Feature .pureFunsEnabled && ! tsym.name.isImpureFunction)
231+ else if defn.isFunctionSymbol(tsym) then toTextFunction(tp)
229232 else if isInfixType(tp) then
230233 val l :: r :: Nil = args : @ unchecked
231234 val opName = tyconName(tycon)
@@ -618,7 +621,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
618621 def toTextAnnot =
619622 toTextLocal(arg) ~~ annotText(annot.symbol.enclosingClass, annot)
620623 def toTextRetainsAnnot =
621- try changePrec(GlobalPrec )(toText (captureSet) ~ " " ~ toText(arg))
624+ try changePrec(GlobalPrec )(toTextCaptureSet (captureSet) ~ " " ~ toText(arg))
622625 catch case ex : IllegalCaptureRef => toTextAnnot
623626 if annot.symbol.maybeOwner == defn.RetainsAnnot
624627 && Feature .ccEnabled && Config .printCaptureSetsAsPrefix && ! printDebug
@@ -737,12 +740,21 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
737740 case ImpureByNameTypeTree (bntpt) =>
738741 " => " ~ toTextLocal(bntpt)
739742 case _ =>
740- changePrec(GlobalPrec )(" {" ~ Text (refs.map(toText), " , " ) ~ " } " ~ toText(parent))
743+ toText(parent) ~ " ^"
744+ ~ changePrec(GlobalPrec )(" {" ~ Text (refs.map(toText), " , " ) ~ " }" )
741745 case _ =>
742746 tree.fallbackToText(this )
743747 }
744748 }
745749
750+ override protected def toTextCapturing (tp : Type , refsText : Text , boxText : Text ): Text = tp match
751+ case tp : AppliedType if defn.isFunctionSymbol(tp.typeSymbol) && ! printDebug =>
752+ boxText ~ toTextFunction(tp, refsText)
753+ case tp : RefinedType if defn.isFunctionOrPolyType(tp) && ! printDebug =>
754+ boxText ~ toTextMethodAsFunction(tp.refinedInfo, isPure = ! tp.typeSymbol.name.isImpureFunction, refsText)
755+ case _ =>
756+ super .toTextCapturing(tp, refsText, boxText)
757+
746758 override def toText [T <: Untyped ](tree : Tree [T ]): Text = controlled {
747759 import untpd ._
748760
0 commit comments