@@ -1037,7 +1037,7 @@ class CheckCaptures extends Recheck, SymTransformer:
10371037 val arrow = if covariant then " ~~>" else " <~~"
10381038 i " adapting $actual $arrow $expected"
10391039
1040- def adapt (actual : Type , expected : Type , covariant : Boolean ): Type = trace(adaptInfo(actual, expected, covariant), recheckr, show = true ) {
1040+ def adapt (actual : Type , expected : Type , covariant : Boolean ): Type = trace(adaptInfo(actual, expected, covariant), recheckr, show = true ):
10411041 if expected.isInstanceOf [WildcardType ] then actual
10421042 else
10431043 // Decompose the actual type into the inner shape type, the capture set and the box status
@@ -1117,7 +1117,22 @@ class CheckCaptures extends Recheck, SymTransformer:
11171117 adaptedType(! boxed)
11181118 else
11191119 adaptedType(boxed)
1120- }
1120+ end adapt
1121+
1122+ /** If result derives from caps.Capability, yet is not a capturing type itself,
1123+ * make its capture set explicit.
1124+ */
1125+ def makeCaptureSetExplicit (result : Type ) = result match
1126+ case CapturingType (_, _) => result
1127+ case _ =>
1128+ if result.derivesFromCapability then
1129+ val cap : CaptureRef = actual match
1130+ case ref : CaptureRef if ref.isTracked =>
1131+ ref
1132+ case _ =>
1133+ defn.captureRoot.termRef // TODO: skolemize?
1134+ CapturingType (result, cap.singletonCaptureSet)
1135+ else result
11211136
11221137 if expected == LhsProto || expected.isSingleton && actual.isSingleton then
11231138 actual
@@ -1133,10 +1148,12 @@ class CheckCaptures extends Recheck, SymTransformer:
11331148 case _ =>
11341149 case _ =>
11351150 val adapted = adapt(actualw.withReachCaptures(actual), expected, covariant = true )
1136- if adapted ne actualw then
1137- capt.println(i " adapt boxed $actual vs $expected ===> $adapted" )
1138- adapted
1139- else actual
1151+ makeCaptureSetExplicit :
1152+ if adapted ne actualw then
1153+ capt.println(i " adapt boxed $actual vs $expected ===> $adapted" )
1154+ adapted
1155+ else
1156+ actual
11401157 end adaptBoxed
11411158
11421159 /** Check overrides again, taking capture sets into account.
0 commit comments