@@ -692,6 +692,9 @@ object CaptureSet:
692692 */
693693 private [CaptureSet ] var rootLimit : Symbol | Null = null
694694
695+ def isBadRoot (elem : Capability )(using Context ): Boolean =
696+ isBadRoot(rootLimit, elem)
697+
695698 private var myClassifier : ClassSymbol = defn.AnyClass
696699 def classifier : ClassSymbol = myClassifier
697700
@@ -749,7 +752,7 @@ object CaptureSet:
749752 assert(elem.isWellformed, elem)
750753 assert(! this .isInstanceOf [HiddenSet ] || summon[VarState ].isSeparating, summon[VarState ])
751754 includeElem(elem)
752- if isBadRoot(rootLimit, elem) then
755+ if isBadRoot(elem) then
753756 rootAddedHandler()
754757 val normElem = if isMaybeSet then elem else elem.stripMaybe
755758 // assert(id != 5 || elems.size != 3, this)
@@ -778,7 +781,7 @@ object CaptureSet:
778781 case _ => foldOver(b, t)
779782 find(false , binder)
780783
781- private def levelOK (elem : Capability )(using Context ): Boolean = elem match
784+ def levelOK (elem : Capability )(using Context ): Boolean = elem match
782785 case _ : FreshCap =>
783786 ! level.isDefined
784787 || ccState.symLevel(elem.ccOwner) <= level
@@ -1246,7 +1249,13 @@ object CaptureSet:
12461249 * when a subsumes check decides that an existential variable `ex` cannot be
12471250 * instantiated to the other capability `other`.
12481251 */
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. """
12501259
12511260 /** Failure indicating that `elem` cannot be included in `cs` */
12521261 case class IncludeFailure (cs : CaptureSet , elem : Capability , levelError : Boolean = false ) extends ErrorNote , Showable :
@@ -1258,6 +1267,29 @@ object CaptureSet:
12581267 res.myTrace = cs1 :: this .myTrace
12591268 res
12601269
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+
12611293 override def toText (printer : Printer ): Text =
12621294 inContext(printer.printerContext):
12631295 if levelError then
@@ -1274,7 +1306,11 @@ object CaptureSet:
12741306 * @param lo the lower type of the orginal type comparison, or NoType if not known
12751307 * @param hi the upper type of the orginal type comparison, or NoType if not known
12761308 */
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)}. """
12781314
12791315 /** A VarState serves as a snapshot mechanism that can undo
12801316 * additions of elements or super sets if an operation fails
0 commit comments