@@ -732,19 +732,26 @@ class CheckCaptures extends Recheck, SymTransformer:
732732 |since its capture set ${qualType.captureSet} is read-only """ ,
733733 tree.srcPos)
734734
735- val selType = mapResultRoots(recheckSelection(tree, qualType, name, disambiguate), tree.symbol)
735+ val origSelType = recheckSelection(tree, qualType, name, disambiguate)
736+ val selType = mapResultRoots(origSelType, tree.symbol)
736737 val selWiden = selType.widen
737738
739+ def capturesResult = origSelType.widenSingleton match
740+ case ExprType (resType) => resType.captureSet.containsResultCapability
741+ case _ => false
742+
738743 // Don't apply the rule
739744 // - on the LHS of assignments, or
740745 // - if the qualifier or selection type is boxed, or
741- // - the selection is either a trackable capture reference or a pure type
746+ // - the selection is either a trackable capture reference or a pure type, or
747+ // - if the selection is of a parameterless method capturing a result cap
742748 if noWiden(selType, pt)
743749 || qualType.isBoxedCapturing
744750 || selType.isBoxedCapturing
745751 || selWiden.isBoxedCapturing
746752 || selType.isTrackableRef
747753 || selWiden.captureSet.isAlwaysEmpty
754+ || capturesResult
748755 then
749756 selType
750757 else
@@ -819,9 +826,8 @@ class CheckCaptures extends Recheck, SymTransformer:
819826 */
820827 protected override
821828 def recheckApplication (tree : Apply , qualType : Type , funType : MethodType , argTypes : List [Type ])(using Context ): Type =
822- val appType = resultToFresh(
823- super .recheckApplication(tree, qualType, funType, argTypes),
824- Origin .ResultInstance (funType, tree.symbol))
829+ val resultType = super .recheckApplication(tree, qualType, funType, argTypes)
830+ val appType = resultToFresh(resultType, Origin .ResultInstance (funType, tree.symbol))
825831 val qualCaptures = qualType.captureSet
826832 val argCaptures =
827833 for (argType, formal) <- argTypes.lazyZip(funType.paramInfos) yield
@@ -830,6 +836,7 @@ class CheckCaptures extends Recheck, SymTransformer:
830836 case appType @ CapturingType (appType1, refs)
831837 if qualType.exists
832838 && ! tree.fun.symbol.isConstructor
839+ && ! resultType.captureSet.containsResultCapability
833840 && qualCaptures.mightSubcapture(refs)
834841 && argCaptures.forall(_.mightSubcapture(refs)) =>
835842 val callCaptures = argCaptures.foldLeft(qualCaptures)(_ ++ _)
0 commit comments