@@ -692,6 +692,9 @@ object CaptureSet:
692
692
*/
693
693
private [CaptureSet ] var rootLimit : Symbol | Null = null
694
694
695
+ def isBadRoot (elem : Capability )(using Context ): Boolean =
696
+ isBadRoot(rootLimit, elem)
697
+
695
698
private var myClassifier : ClassSymbol = defn.AnyClass
696
699
def classifier : ClassSymbol = myClassifier
697
700
@@ -749,7 +752,7 @@ object CaptureSet:
749
752
assert(elem.isWellformed, elem)
750
753
assert(! this .isInstanceOf [HiddenSet ] || summon[VarState ].isSeparating, summon[VarState ])
751
754
includeElem(elem)
752
- if isBadRoot(rootLimit, elem) then
755
+ if isBadRoot(elem) then
753
756
rootAddedHandler()
754
757
val normElem = if isMaybeSet then elem else elem.stripMaybe
755
758
// assert(id != 5 || elems.size != 3, this)
@@ -778,7 +781,7 @@ object CaptureSet:
778
781
case _ => foldOver(b, t)
779
782
find(false , binder)
780
783
781
- private def levelOK (elem : Capability )(using Context ): Boolean = elem match
784
+ def levelOK (elem : Capability )(using Context ): Boolean = elem match
782
785
case _ : FreshCap =>
783
786
! level.isDefined
784
787
|| ccState.symLevel(elem.ccOwner) <= level
@@ -1246,7 +1249,13 @@ object CaptureSet:
1246
1249
* when a subsumes check decides that an existential variable `ex` cannot be
1247
1250
* instantiated to the other capability `other`.
1248
1251
*/
1249
- case class ExistentialSubsumesFailure (val ex : ResultCap , val other : Capability ) extends ErrorNote
1252
+ case class ExistentialSubsumesFailure (val ex : ResultCap , val other : Capability ) extends ErrorNote :
1253
+ def description (using Context ): String =
1254
+ def reason =
1255
+ if other.isTerminalCapability then " "
1256
+ else " since that capability is not a `Sharable` capability"
1257
+ i """ the existential capture root in ${ex.originalBinder.resType}
1258
+ |cannot subsume the capability $other$reason. """
1250
1259
1251
1260
/** Failure indicating that `elem` cannot be included in `cs` */
1252
1261
case class IncludeFailure (cs : CaptureSet , elem : Capability , levelError : Boolean = false ) extends ErrorNote , Showable :
@@ -1258,6 +1267,29 @@ object CaptureSet:
1258
1267
res.myTrace = cs1 :: this .myTrace
1259
1268
res
1260
1269
1270
+ def description (using Context ): String = cs match
1271
+ case cs : Var =>
1272
+ if ! cs.levelOK(elem) then
1273
+ val levelStr = elem match
1274
+ case ref : TermRef => i " , defined in ${ref.symbol.maybeOwner}"
1275
+ case _ => " "
1276
+ i """ capability ${elem}$levelStr
1277
+ |cannot be included in outer capture set $cs"""
1278
+ else if ! elem.tryClassifyAs(cs.classifier) then
1279
+ i """ capability ${elem} is not classified as ${cs.classifier}, therefore it
1280
+ |cannot be included in capture set $cs of ${cs.classifier} elements """
1281
+ else if cs.isBadRoot(elem) then
1282
+ elem match
1283
+ case elem : FreshCap =>
1284
+ i """ local capability $elem created in ${elem.ccOwner}
1285
+ |cannot be included in outer capture set $cs"""
1286
+ case _ =>
1287
+ i " universal capability $elem cannot be included in capture set $cs"
1288
+ else
1289
+ i " capability $elem cannot be included in capture set $cs"
1290
+ case _ =>
1291
+ i " capability $elem is not included in capture set $cs"
1292
+
1261
1293
override def toText (printer : Printer ): Text =
1262
1294
inContext(printer.printerContext):
1263
1295
if levelError then
@@ -1274,7 +1306,11 @@ object CaptureSet:
1274
1306
* @param lo the lower type of the orginal type comparison, or NoType if not known
1275
1307
* @param hi the upper type of the orginal type comparison, or NoType if not known
1276
1308
*/
1277
- case class MutAdaptFailure (cs : CaptureSet , lo : Type = NoType , hi : Type = NoType ) extends ErrorNote
1309
+ case class MutAdaptFailure (cs : CaptureSet , lo : Type = NoType , hi : Type = NoType ) extends ErrorNote :
1310
+ def description (using Context ): String =
1311
+ def ofType (tp : Type ) = if tp.exists then i " of the mutable type $tp" else " of a mutable type"
1312
+ i """ $cs is an exclusive capture set ${ofType(hi)},
1313
+ |it cannot subsume a read-only capture set ${ofType(lo)}. """
1278
1314
1279
1315
/** A VarState serves as a snapshot mechanism that can undo
1280
1316
* additions of elements or super sets if an operation fails
0 commit comments