@@ -58,6 +58,7 @@ object Capabilities:
5858 trait RootCapability extends Capability :
5959 val rootId = nextRootId
6060 nextRootId += 1
61+ def descr (using Context ): String
6162
6263 /** The base trait of all capabilties represented as types */
6364 trait CoreCapability extends TypeProxy , Capability :
@@ -120,6 +121,7 @@ object Capabilities:
120121 */
121122 @ sharable // We override below all operations that access internal capability state
122123 object GlobalCap extends RootCapability :
124+ def descr (using Context ) = " the universal root capability"
123125 override val maybe = Maybe (this )
124126 override val readOnly = ReadOnly (this )
125127 override def reach = unsupported(" cap.reach" )
@@ -136,13 +138,21 @@ object Capabilities:
136138 * for diagnostics
137139 */
138140 case class FreshCap private (owner : Symbol , origin : Origin )(using @ constructorOnly ctx : Context ) extends RootCapability :
139- val hiddenSet = CaptureSet .HiddenSet (owner)
140- hiddenSet.owningCap = this
141+ val hiddenSet = CaptureSet .HiddenSet (owner, this : @ unchecked )
142+ // fails initialization check without the @unchecked
141143
142144 override def equals (that : Any ) = that match
143145 case that : FreshCap => this eq that
144146 case _ => false
145147
148+ def descr (using Context ) =
149+ val originStr = origin match
150+ case Origin .InDecl (sym) if sym.exists =>
151+ origin.explanation
152+ case _ =>
153+ i " created in ${hiddenSet.owner.sanitizedDescription}${origin.explanation}"
154+ i " a fresh root capability $originStr"
155+
146156 object FreshCap :
147157 def apply (origin : Origin )(using Context ): FreshCap | GlobalCap .type =
148158 if ccConfig.useSepChecks then FreshCap (ctx.owner, origin)
@@ -225,6 +235,9 @@ object Capabilities:
225235 rcap.myOrigin = primary
226236 primary.variants += rcap
227237 rcap
238+
239+ def descr (using Context ) =
240+ i " a root capability associated with the result type of $binder"
228241 end ResultCap
229242
230243 /** A trait for references in CaptureSets. These can be NamedTypes, ThisTypes or ParamRefs,
@@ -545,7 +558,7 @@ object Capabilities:
545558 case y : ResultCap => vs.unify(x, y)
546559 case _ => y.derivesFromSharedCapability
547560 if ! result then
548- ccState.addNote (CaptureSet .ExistentialSubsumesFailure (x, y))
561+ TypeComparer .addErrorNote (CaptureSet .ExistentialSubsumesFailure (x, y))
549562 result
550563 case GlobalCap =>
551564 y match
0 commit comments