@@ -18,7 +18,7 @@ import transform.SymUtils.*
18
18
import transform .{Recheck , PreRecheck }
19
19
import Recheck .*
20
20
import scala .collection .mutable
21
- import CaptureSet .{withCaptureSetsExplained , IdempotentCaptRefMap }
21
+ import CaptureSet .{withCaptureSetsExplained , IdempotentCaptRefMap , CompareResult }
22
22
import StdNames .nme
23
23
import NameKinds .DefaultGetterName
24
24
import reporting .trace
@@ -262,21 +262,25 @@ class CheckCaptures extends Recheck, SymTransformer:
262
262
def assertSub (cs1 : CaptureSet , cs2 : CaptureSet )(using Context ) =
263
263
assert(cs1.subCaptures(cs2, frozen = false ).isOK, i " $cs1 is not a subset of $cs2" )
264
264
265
+ def checkOK (res : CompareResult , prefix : => String , pos : SrcPos )(using Context ): Unit =
266
+ if ! res.isOK then
267
+ def toAdd : String = CaptureSet .levelErrors.toAdd.mkString
268
+ report.error(em " $prefix included in the allowed capture set ${res.blocking}$toAdd" , pos)
269
+
265
270
/** Check subcapturing `{elem} <: cs`, report error on failure */
266
271
def checkElem (elem : CaptureRef , cs : CaptureSet , pos : SrcPos )(using Context ) =
267
- val res = elem.singletonCaptureSet.subCaptures(cs, frozen = false )
268
- if ! res.isOK then
269
- report.error(em " $elem cannot be referenced here; it is not included in the allowed capture set ${res.blocking}" , pos)
272
+ checkOK(
273
+ elem.singletonCaptureSet.subCaptures(cs, frozen = false ),
274
+ i " $elem cannot be referenced here; it is not " ,
275
+ pos)
270
276
271
277
/** Check subcapturing `cs1 <: cs2`, report error on failure */
272
278
def checkSubset (cs1 : CaptureSet , cs2 : CaptureSet , pos : SrcPos )(using Context ) =
273
- val res = cs1.subCaptures(cs2, frozen = false )
274
- if ! res.isOK then
275
- def header =
279
+ checkOK(
280
+ cs1.subCaptures(cs2, frozen = false ),
276
281
if cs1.elems.size == 1 then i " reference ${cs1.elems.toList}%, % is not "
277
- else i " references $cs1 are not all "
278
- def toAdd : String = CaptureSet .levelErrors.toAdd.mkString
279
- report.error(em " $header included in allowed capture set ${res.blocking}$toAdd" , pos)
282
+ else i " references $cs1 are not all " ,
283
+ pos)
280
284
281
285
/** The current environment */
282
286
private var curEnv : Env = inContext(ictx):
0 commit comments