@@ -159,17 +159,22 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
159159 private def arrow (isGiven : Boolean , isPure : Boolean ): String =
160160 (if isGiven then " ?" else " " ) + (if isPure then " ->" else " =>" )
161161
162- private def toTextFunction (tp : AppliedType , refs : Text = Str ( " " ) ): Text =
162+ private def toTextFunction (tp : AppliedType , refs : GeneralCaptureSet | Null ): Text =
163163 val AppliedType (tycon, args) = (tp : @ unchecked)
164164 val tsym = tycon.typeSymbol
165- val isContextual = tsym.name.isContextFunction
166- val capturesRoot = refs == rootSetText
167- val isPure =
168- Feature .pureFunsEnabled && ! tsym.name.isImpureFunction && ! capturesRoot
169- toTextFunction(args.init, args.last, tp, refs.provided(! capturesRoot), isContextual, isPure)
170-
171- private def toTextFunction (args : List [Type ], res : Type , fn : MethodType | AppliedType , refs : Text ,
172- isContextual : Boolean , isPure : Boolean ): Text =
165+ toTextFunction(args.init, args.last, tp, refs,
166+ isContextual = tsym.name.isContextFunction,
167+ isPure = Feature .pureFunsEnabled && ! tsym.name.isImpureFunction)
168+
169+ protected def funMiddleText (isContextual : Boolean , isPure : Boolean , refs : GeneralCaptureSet | Null ): Text =
170+ val (printPure, refsText) =
171+ if refs == null then (isPure, Str (" " ))
172+ else if isUniversalCaptureSet(refs) then (false , Str (" " ))
173+ else (isPure, toTextGeneralCaptureSet(refs))
174+ arrow(isContextual, printPure) ~ refsText
175+
176+ private def toTextFunction (args : List [Type ], res : Type , fn : MethodType | AppliedType ,
177+ refs : GeneralCaptureSet | Null , isContextual : Boolean , isPure : Boolean ): Text =
173178 changePrec(GlobalPrec ):
174179 val argStr : Text = args match
175180 case arg :: Nil if ! defn.isDirectTupleNType(arg) && ! isContextual =>
@@ -179,30 +184,29 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
179184 " ("
180185 ~ argsText(args)
181186 ~ " )"
182- argStr ~ " " ~ arrow(isContextual, isPure) ~ refs ~ " "
187+ argStr ~ " "
188+ ~ funMiddleText(isContextual, isPure, refs) ~ " "
183189 ~ fn.match
184190 case fn : MethodType => CCState .inNewExistentialScope(fn)(argText(res))
185191 case _ => argText(res)
186192
187- protected def toTextMethodAsFunction (info : Type , isPure : Boolean , refs : Text = Str ( " " ) ): Text =
193+ protected def toTextMethodAsFunction (info : Type , isPure : Boolean , refs : GeneralCaptureSet | Null ): Text =
188194 def recur (tp : Type , enclInfo : MethodType | Null ): Text = tp match
189195 case tp : MethodType =>
190196 val isContextual = tp.isImplicitMethod
191- val capturesRoot = refs == rootSetText
192197 if cc.isCaptureCheckingOrSetup
193198 && tp.allParamNamesSynthetic
194199 && ! tp.looksResultDependent && ! tp.looksParamDependent
195200 && ! showUniqueIds && ! printDebug && ! printFresh
196- then
201+ then
197202 // cc.Setup converts all functions to dependent functions. Undo that when printing.
198- toTextFunction(tp.paramInfos, tp.resType, tp, refs.provided( ! capturesRoot) , isContextual, isPure && ! capturesRoot )
203+ toTextFunction(tp.paramInfos, tp.resType, tp, refs, isContextual, isPure)
199204 else
200205 changePrec(GlobalPrec ):
201206 " ("
202207 ~ paramsText(tp)
203208 ~ " ) "
204- ~ arrow(isContextual, isPure && ! capturesRoot)
205- ~ refs.provided(! capturesRoot)
209+ ~ funMiddleText(isContextual, isPure, refs)
206210 ~ " "
207211 ~ recur(tp.resultType, tp)
208212 case tp : PolyType =>
@@ -274,7 +278,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
274278 case _ =>
275279 val tsym = tycon.typeSymbol
276280 if tycon.isRepeatedParam then toTextLocal(args.head) ~ " *"
277- else if defn.isFunctionSymbol(tsym) then toTextFunction(tp)
281+ else if defn.isFunctionSymbol(tsym) then toTextFunction(tp, null )
278282 else if isInfixType(tp) then
279283 val l :: r :: Nil = args : @ unchecked
280284 val opName = tyconName(tycon)
@@ -303,8 +307,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
303307 toTextMethodAsFunction(tp.refinedInfo,
304308 isPure = Feature .pureFunsEnabled && ! tp.typeSymbol.name.isImpureFunction,
305309 refs = tp.parent match
306- case CapturingType (_, cs) => toTextCaptureSet(cs)
307- case _ => " " )
310+ case CapturingType (_, cs) => cs
311+ case _ => null )
308312 case tp : TypeRef =>
309313 if (tp.symbol.isAnonymousClass && ! showUniqueIds)
310314 toText(tp.info)
@@ -320,7 +324,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
320324 case tp : ClassInfo =>
321325 if tp.cls.derivesFrom(defn.PolyFunctionClass ) then
322326 tp.member(nme.apply).info match
323- case info : PolyType => toTextMethodAsFunction(info, isPure = false )
327+ case info : PolyType => toTextMethodAsFunction(info, isPure = false , refs = null )
324328 case _ => toTextParents(tp.parents) ~~ " {...}"
325329 else toTextParents(tp.parents) ~~ " {...}"
326330 case JavaArrayType (elemtp) =>
@@ -849,13 +853,13 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
849853 }
850854 }
851855
852- override protected def toTextCapturing (tp : Type , refsText : Text , boxText : Text ): Text = tp match
856+ override protected def toTextCapturing (tp : Type , refs : GeneralCaptureSet , boxText : Text ): Text = tp match
853857 case tp : AppliedType if defn.isFunctionSymbol(tp.typeSymbol) && ! printDebug =>
854- boxText ~ toTextFunction(tp, refsText )
858+ boxText ~ toTextFunction(tp, refs )
855859 case tp : RefinedType if defn.isFunctionType(tp) && ! printDebug =>
856- boxText ~ toTextMethodAsFunction(tp.refinedInfo, isPure = ! tp.typeSymbol.name.isImpureFunction, refsText )
860+ boxText ~ toTextMethodAsFunction(tp.refinedInfo, isPure = ! tp.typeSymbol.name.isImpureFunction, refs )
857861 case _ =>
858- super .toTextCapturing(tp, refsText , boxText)
862+ super .toTextCapturing(tp, refs , boxText)
859863
860864 override def toText [T <: Untyped ](tree : Tree [T ]): Text = controlled {
861865 import untpd .*
0 commit comments