@@ -159,17 +159,22 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
159
159
private def arrow (isGiven : Boolean , isPure : Boolean ): String =
160
160
(if isGiven then " ?" else " " ) + (if isPure then " ->" else " =>" )
161
161
162
- private def toTextFunction (tp : AppliedType , refs : Text = Str ( " " ) ): Text =
162
+ private def toTextFunction (tp : AppliedType , refs : GeneralCaptureSet | Null ): Text =
163
163
val AppliedType (tycon, args) = (tp : @ unchecked)
164
164
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 =
173
178
changePrec(GlobalPrec ):
174
179
val argStr : Text = args match
175
180
case arg :: Nil if ! defn.isDirectTupleNType(arg) && ! isContextual =>
@@ -179,30 +184,29 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
179
184
" ("
180
185
~ argsText(args)
181
186
~ " )"
182
- argStr ~ " " ~ arrow(isContextual, isPure) ~ refs ~ " "
187
+ argStr ~ " "
188
+ ~ funMiddleText(isContextual, isPure, refs) ~ " "
183
189
~ fn.match
184
190
case fn : MethodType => CCState .inNewExistentialScope(fn)(argText(res))
185
191
case _ => argText(res)
186
192
187
- protected def toTextMethodAsFunction (info : Type , isPure : Boolean , refs : Text = Str ( " " ) ): Text =
193
+ protected def toTextMethodAsFunction (info : Type , isPure : Boolean , refs : GeneralCaptureSet | Null ): Text =
188
194
def recur (tp : Type , enclInfo : MethodType | Null ): Text = tp match
189
195
case tp : MethodType =>
190
196
val isContextual = tp.isImplicitMethod
191
- val capturesRoot = refs == rootSetText
192
197
if cc.isCaptureCheckingOrSetup
193
198
&& tp.allParamNamesSynthetic
194
199
&& ! tp.looksResultDependent && ! tp.looksParamDependent
195
200
&& ! showUniqueIds && ! printDebug && ! printFresh
196
- then
201
+ then
197
202
// 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)
199
204
else
200
205
changePrec(GlobalPrec ):
201
206
" ("
202
207
~ paramsText(tp)
203
208
~ " ) "
204
- ~ arrow(isContextual, isPure && ! capturesRoot)
205
- ~ refs.provided(! capturesRoot)
209
+ ~ funMiddleText(isContextual, isPure, refs)
206
210
~ " "
207
211
~ recur(tp.resultType, tp)
208
212
case tp : PolyType =>
@@ -274,7 +278,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
274
278
case _ =>
275
279
val tsym = tycon.typeSymbol
276
280
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 )
278
282
else if isInfixType(tp) then
279
283
val l :: r :: Nil = args : @ unchecked
280
284
val opName = tyconName(tycon)
@@ -303,8 +307,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
303
307
toTextMethodAsFunction(tp.refinedInfo,
304
308
isPure = Feature .pureFunsEnabled && ! tp.typeSymbol.name.isImpureFunction,
305
309
refs = tp.parent match
306
- case CapturingType (_, cs) => toTextCaptureSet(cs)
307
- case _ => " " )
310
+ case CapturingType (_, cs) => cs
311
+ case _ => null )
308
312
case tp : TypeRef =>
309
313
if (tp.symbol.isAnonymousClass && ! showUniqueIds)
310
314
toText(tp.info)
@@ -320,7 +324,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
320
324
case tp : ClassInfo =>
321
325
if tp.cls.derivesFrom(defn.PolyFunctionClass ) then
322
326
tp.member(nme.apply).info match
323
- case info : PolyType => toTextMethodAsFunction(info, isPure = false )
327
+ case info : PolyType => toTextMethodAsFunction(info, isPure = false , refs = null )
324
328
case _ => toTextParents(tp.parents) ~~ " {...}"
325
329
else toTextParents(tp.parents) ~~ " {...}"
326
330
case JavaArrayType (elemtp) =>
@@ -849,13 +853,13 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
849
853
}
850
854
}
851
855
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
853
857
case tp : AppliedType if defn.isFunctionSymbol(tp.typeSymbol) && ! printDebug =>
854
- boxText ~ toTextFunction(tp, refsText )
858
+ boxText ~ toTextFunction(tp, refs )
855
859
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 )
857
861
case _ =>
858
- super .toTextCapturing(tp, refsText , boxText)
862
+ super .toTextCapturing(tp, refs , boxText)
859
863
860
864
override def toText [T <: Untyped ](tree : Tree [T ]): Text = controlled {
861
865
import untpd .*
0 commit comments