@@ -36,6 +36,8 @@ object CaptureDefs:
36
36
qctx.reflect.Symbol .requiredClass(" scala.annotation.internal.readOnlyCapability" )
37
37
def RequiresCapabilityAnnot (using qctx : Quotes ) =
38
38
qctx.reflect.Symbol .requiredClass(" scala.annotation.internal.requiresCapability" )
39
+ def OnlyCapabilityAnnot (using qctx : Quotes ) =
40
+ qctx.reflect.Symbol .requiredClass(" scala.annotation.internal.onlyCapability" )
39
41
40
42
def LanguageExperimental (using qctx : Quotes ) =
41
43
qctx.reflect.Symbol .requiredPackage(" scala.language.experimental" )
@@ -71,6 +73,9 @@ extension (using qctx: Quotes)(ann: qctx.reflect.Symbol)
71
73
72
74
def isReadOnlyCapabilityAnnot : Boolean =
73
75
ann == CaptureDefs .ReadOnlyCapabilityAnnot
76
+
77
+ def isOnlyCapabilityAnnot : Boolean =
78
+ ann == CaptureDefs .OnlyCapabilityAnnot
74
79
end extension
75
80
76
81
extension (using qctx : Quotes )(tpe : qctx.reflect.TypeRepr ) // FIXME clean up and have versions on Symbol for those
@@ -171,6 +176,17 @@ object ReadOnlyCapability:
171
176
case _ => None
172
177
end ReadOnlyCapability
173
178
179
+ object OnlyCapability :
180
+ def unapply (using qctx : Quotes )(ty : qctx.reflect.TypeRepr ): Option [(qctx.reflect.TypeRepr , qctx.reflect.Symbol )] =
181
+ import qctx .reflect ._
182
+ ty match
183
+ case AnnotatedType (base, app @ Apply (TypeApply (Select (New (annot), _), _), Nil )) if annot.tpe.typeSymbol.isOnlyCapabilityAnnot =>
184
+ app.tpe.typeArgs.head.classSymbol.match
185
+ case Some (clazzsym) => Some ((base, clazzsym))
186
+ case None => None
187
+ case _ => None
188
+ end OnlyCapability
189
+
174
190
/** Decompose capture sets in the union-type-encoding into the sequence of atomic `TypeRepr`s.
175
191
* Returns `None` if the type is not a capture set.
176
192
*/
@@ -187,8 +203,9 @@ def decomposeCaptureRefs(using qctx: Quotes)(typ0: qctx.reflect.TypeRepr): Optio
187
203
case t @ ParamRef (_, _) => include(t)
188
204
case t @ ReachCapability (_) => include(t)
189
205
case t @ ReadOnlyCapability (_) => include(t)
190
- case t : TypeRef => include(t) // FIXME: does this need a more refined check?
191
- case _ => report.warning(s " Unexpected type tree $typ while trying to extract capture references from $typ0" ); false // TODO remove warning eventually
206
+ case t @ OnlyCapability (_, _) => include(t)
207
+ case t : TypeRef => include(t)
208
+ case _ => report.warning(s " Unexpected type tree $typ while trying to extract capture references from $typ0" ); false
192
209
if traverse(typ0) then Some (buffer.toList) else None
193
210
end decomposeCaptureRefs
194
211
0 commit comments