@@ -1037,7 +1037,7 @@ class CheckCaptures extends Recheck, SymTransformer:
1037
1037
val arrow = if covariant then " ~~>" else " <~~"
1038
1038
i " adapting $actual $arrow $expected"
1039
1039
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 ):
1041
1041
if expected.isInstanceOf [WildcardType ] then actual
1042
1042
else
1043
1043
// 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:
1117
1117
adaptedType(! boxed)
1118
1118
else
1119
1119
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
1121
1136
1122
1137
if expected == LhsProto || expected.isSingleton && actual.isSingleton then
1123
1138
actual
@@ -1133,10 +1148,12 @@ class CheckCaptures extends Recheck, SymTransformer:
1133
1148
case _ =>
1134
1149
case _ =>
1135
1150
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
1140
1157
end adaptBoxed
1141
1158
1142
1159
/** Check overrides again, taking capture sets into account.
0 commit comments