@@ -594,6 +594,12 @@ class CheckCaptures extends Recheck, SymTransformer:
594
594
if sym.exists && curEnv.kind != EnvKind .Boxed then
595
595
markFree(capturedVars(sym).filter(isRetained), tree)
596
596
597
+ /** Include references captured by the type of the function. */
598
+ def includeFunctionCaptures (qualType : Type , tree : Apply )(using Context ): Unit =
599
+ if ccConfig.caplessLike && ! qualType.isAlwaysPure then
600
+ val funCaptures = qualType.captureSet
601
+ markFree(funCaptures, tree)
602
+
597
603
/** If `tp` (possibly after widening singletons) is an ExprType
598
604
* of a parameterless method, map Result instances in it to Fresh instances
599
605
*/
@@ -815,12 +821,15 @@ class CheckCaptures extends Recheck, SymTransformer:
815
821
val argCaptures =
816
822
for (argType, formal) <- argTypes.lazyZip(funType.paramInfos) yield
817
823
if formal.hasAnnotation(defn.UseAnnot ) then argType.deepCaptureSet else argType.captureSet
824
+ if ccConfig.caplessLike then
825
+ includeFunctionCaptures(qualType, tree)
818
826
appType match
819
827
case appType @ CapturingType (appType1, refs)
820
828
if qualType.exists
821
829
&& ! tree.fun.symbol.isConstructor
822
830
&& qualCaptures.mightSubcapture(refs)
823
- && argCaptures.forall(_.mightSubcapture(refs)) =>
831
+ && argCaptures.forall(_.mightSubcapture(refs))
832
+ && ! ccConfig.caplessLike =>
824
833
val callCaptures = argCaptures.foldLeft(qualCaptures)(_ ++ _)
825
834
appType.derivedCapturingType(appType1, callCaptures)
826
835
.showing(i " narrow $tree: $appType, refs = $refs, qual-cs = ${qualType.captureSet} = $result" , capt)
0 commit comments