@@ -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)
@@ -529,9 +530,19 @@ trait TypesSupport:
529
530
case other => other.reduce((r, e) => r ++ (List (Plain (" , " )) ++ e))
530
531
Plain (" {" ) :: (res1 ++ List (Plain (" }" )))
531
532
533
+ // Within the context of `elideThis`, some capabilities can actually be pure.
534
+ private def isCapturedInContext (using Quotes )(ref : reflect.TypeRepr )(using elideThis : reflect.ClassDef ): Boolean =
535
+ import reflect ._
536
+ ref match
537
+ case ReachCapability (c) => isCapturedInContext(c)
538
+ case ReadOnlyCapability (c) => isCapturedInContext(c)
539
+ case ThisType (tr) => ! elideThis.symbol.typeRef.isPureClass(elideThis) /* is the current class pure? */
540
+ case t => ! t.isPureClass(elideThis)
541
+
532
542
private def emitCapturing (using Quotes )(refs : List [reflect.TypeRepr ], skipThisTypePrefix : Boolean )(using elideThis : reflect.ClassDef , originalOwner : reflect.Symbol ): SSignature =
533
543
import reflect ._
534
- Keyword (" ^" ) :: emitCaptureSet(refs, skipThisTypePrefix)
544
+ val refs0 = refs.filter(isCapturedInContext)
545
+ if refs0.isEmpty then Nil else Keyword (" ^" ) :: emitCaptureSet(refs0, skipThisTypePrefix)
535
546
536
547
private def emitFunctionArrow (using Quotes )(funTy : reflect.TypeRepr , captures : Option [List [reflect.TypeRepr ]], skipThisTypePrefix : Boolean )(using elideThis : reflect.ClassDef , originalOwner : reflect.Symbol ): SSignature =
537
548
import reflect ._
@@ -559,4 +570,4 @@ trait TypesSupport:
559
570
case refs => Keyword (prefix + " ->" ) :: emitCaptureSet(refs, skipThisTypePrefix)
560
571
561
572
private def emitByNameArrow (using Quotes )(captures : Option [List [reflect.TypeRepr ]], skipThisTypePrefix : Boolean )(using elideThis : reflect.ClassDef , originalOwner : reflect.Symbol ): SSignature =
562
- emitFunctionArrow(CaptureDefs .Function1 .typeRef, captures, skipThisTypePrefix)
573
+ emitFunctionArrow(CaptureDefs .Function1 .typeRef, captures, skipThisTypePrefix)
0 commit comments