@@ -141,6 +141,7 @@ trait TypesSupport:
141
141
case t : Refinement if t.isFunctionType =>
142
142
inner(base, skipThisTypePrefix)(using indent = indent, skipTypeSuffix = skipTypeSuffix, inCC = Some (refs))
143
143
case t if t.isCapSet => emitCaptureSet(refs, skipThisTypePrefix, omitCap = false )
144
+ case t if t.isPureClass(elideThis) => inner(base, skipThisTypePrefix)
144
145
case t => inner(base, skipThisTypePrefix) ++ emitCapturing(refs, skipThisTypePrefix)
145
146
case AnnotatedType (tpe, _) =>
146
147
inner(tpe, skipThisTypePrefix)
@@ -527,9 +528,19 @@ trait TypesSupport:
527
528
case other => other.reduce((r, e) => r ++ (List (Plain (" , " )) ++ e))
528
529
Plain (" {" ) :: (res1 ++ List (Plain (" }" )))
529
530
531
+ // Within the context of `elideThis`, some capabilities can actually be pure.
532
+ private def isCapturedInContext (using Quotes )(ref : reflect.TypeRepr )(using elideThis : reflect.ClassDef ): Boolean =
533
+ import reflect ._
534
+ ref match
535
+ case ReachCapability (c) => isCapturedInContext(c)
536
+ case ReadOnlyCapability (c) => isCapturedInContext(c)
537
+ case ThisType (tr) => ! elideThis.symbol.typeRef.isPureClass(elideThis) /* is the current class pure? */
538
+ case t => ! t.isPureClass(elideThis)
539
+
530
540
private def emitCapturing (using Quotes )(refs : List [reflect.TypeRepr ], skipThisTypePrefix : Boolean )(using elideThis : reflect.ClassDef , originalOwner : reflect.Symbol ): SSignature =
531
541
import reflect ._
532
- Keyword (" ^" ) :: emitCaptureSet(refs, skipThisTypePrefix)
542
+ val refs0 = refs.filter(isCapturedInContext)
543
+ if refs0.isEmpty then Nil else Keyword (" ^" ) :: emitCaptureSet(refs0, skipThisTypePrefix)
533
544
534
545
private def emitFunctionArrow (using Quotes )(funTy : reflect.TypeRepr , captures : Option [List [reflect.TypeRepr ]], skipThisTypePrefix : Boolean )(using elideThis : reflect.ClassDef , originalOwner : reflect.Symbol ): SSignature =
535
546
import reflect ._
@@ -557,4 +568,4 @@ trait TypesSupport:
557
568
case refs => Keyword (prefix + " ->" ) :: emitCaptureSet(refs, skipThisTypePrefix)
558
569
559
570
private def emitByNameArrow (using Quotes )(captures : Option [List [reflect.TypeRepr ]], skipThisTypePrefix : Boolean )(using elideThis : reflect.ClassDef , originalOwner : reflect.Symbol ): SSignature =
560
- emitFunctionArrow(CaptureDefs .Function1 .typeRef, captures, skipThisTypePrefix)
571
+ emitFunctionArrow(CaptureDefs .Function1 .typeRef, captures, skipThisTypePrefix)
0 commit comments