@@ -1324,12 +1324,25 @@ object CaptureSet:
13241324 res.myTrace = cs1 :: this .myTrace
13251325 res
13261326
1327- def render (using Context ) =
1327+ override def prefix (using Context ) = cs match
1328+ case cs : Var =>
1329+ ! cs.levelOK(elem)
1330+ || cs.isBadRoot(elem) && elem.isInstanceOf [FreshCap ]
1331+ case _ =>
1332+ false
1333+
1334+ def trailing (msg : String )(using Context ): String =
13281335 i """
13291336 |
1330- |Note that $description . """
1337+ |Note that $msg . """
13311338
1332- private def description (using Context ): String =
1339+ def leading (msg : String )(using Context ): String =
1340+ i """ $msg.
1341+ |The leakage occurred when trying to match the following types:
1342+ |
1343+ | """
1344+
1345+ def render (using Context ): String =
13331346 def why =
13341347 val reasons = cs.elems.toList.collect:
13351348 case c : FreshCap if ! c.acceptsLevelOf(elem) =>
@@ -1340,27 +1353,33 @@ object CaptureSet:
13401353 else reasons.mkString(" \n because " , " \n and " , " " )
13411354 cs match
13421355 case cs : Var =>
1356+ def ownerStr =
1357+ if ! cs.description.isEmpty then " " else cs.owner.qualString(" which is owned by" )
13431358 if ! cs.levelOK(elem) then
1344- val levelStr = elem match
1345- case ref : TermRef => i " , defined in ${ref.symbol.maybeOwner}\n "
1346- case _ => " "
1347- val ownerStr =
1348- if cs.owner.exists then s " which is owned by ${cs.owner}" else " "
1349- i """ ${elem.showAsCapability}${levelStr}cannot be included in outer capture set $cs$ownerStr"""
1359+ val outlivesStr = elem match
1360+ case ref : TermRef => i " ${ref.symbol.maybeOwner.qualString(" defined in" )} outlives its scope: \n "
1361+ case _ => " outlives its scope: "
1362+ leading :
1363+ i """ Capability ${elem.showAsCapability}${outlivesStr}it leaks into outer capture set $cs$ownerStr"""
13501364 else if ! elem.tryClassifyAs(cs.classifier) then
1351- i """ ${elem.showAsCapability} is not classified as ${cs.classifier}, therefore it
1365+ trailing :
1366+ i """ capability ${elem.showAsCapability} is not classified as ${cs.classifier}, therefore it
13521367 |cannot be included in capture set $cs of ${cs.classifier.name} elements """
13531368 else if cs.isBadRoot(elem) then
13541369 elem match
13551370 case elem : FreshCap =>
1356- i """ local ${elem.showAsCapability} created in ${elem.ccOwner}
1357- |cannot be included in outer capture set $cs"""
1371+ leading :
1372+ i """ Local capability ${elem.showAsCapability} created in ${elem.ccOwner} outlives its scope:
1373+ |It leaks into outer capture set $cs$ownerStr"""
13581374 case _ =>
1359- i " universal ${elem.showAsCapability} cannot be included in capture set $cs"
1375+ trailing :
1376+ i " universal capability ${elem.showAsCapability} cannot be included in capture set $cs"
13601377 else
1361- i " ${elem.showAsCapability} cannot be included in capture set $cs"
1378+ trailing :
1379+ i " capability ${elem.showAsCapability} cannot be included in capture set $cs"
13621380 case _ =>
1363- i " ${elem.showAsCapability} is not included in capture set $cs$why"
1381+ trailing :
1382+ i " capability ${elem.showAsCapability} is not included in capture set $cs$why"
13641383
13651384 override def toText (printer : Printer ): Text =
13661385 inContext(printer.printerContext):
0 commit comments