@@ -98,24 +98,23 @@ object CheckCaptures:
9898 * This check is performed at Typer.
9999 */
100100 def checkWellformed (parent : Tree , ann : Tree )(using Context ): Unit =
101- def check (elem : Type , pos : SrcPos ): Unit = elem match
102- case ref : Capability =>
101+ def check (elem : Type ): Unit = elem match
102+ case ref : TypeRef =>
103+ val refSym = ref.symbol
104+ if refSym.isType && ! refSym.info.derivesFrom(defn.Caps_CapSet ) then
105+ report.error(em " $elem is not a legal element of a capture set " , ann.srcPos)
106+ case ref : CoreCapability =>
103107 if ! ref.isTrackableRef && ! ref.isCapRef then
104- report.error(em " $elem cannot be tracked since it is not a parameter or local value " , pos)
108+ report.error(em " $elem cannot be tracked since it is not a parameter or local value " , ann.srcPos)
109+ case ReachCapability (ref) =>
110+ check(ref)
111+ if ref.isCapRef then
112+ report.error(em " Cannot form a reach capability from `cap` " , ann.srcPos)
113+ case ReadOnlyCapability (ref) =>
114+ check(ref)
105115 case tpe =>
106- report.error(em " $elem: $tpe is not a legal element of a capture set " , pos)
107- for elem <- ann.retainedSet.retainedElementsRaw do
108- elem match
109- case ref : TypeRef =>
110- val refSym = ref.symbol
111- if refSym.isType && ! refSym.info.derivesFrom(defn.Caps_CapSet ) then
112- report.error(em " $elem is not a legal element of a capture set " , ann.srcPos)
113- case ReachCapability (ref) =>
114- check(ref, ann.srcPos)
115- case ReadOnlyCapability (ref) =>
116- check(ref, ann.srcPos)
117- case _ =>
118- check(elem, ann.srcPos)
116+ report.error(em " $elem: $tpe is not a legal element of a capture set " , ann.srcPos)
117+ ann.retainedSet.retainedElementsRaw.foreach(check)
119118
120119 /** Under the sealed policy, report an error if some part of `tp` contains the
121120 * root capability in its capture set or if it refers to a type parameter that
0 commit comments