@@ -18,7 +18,7 @@ import util.{SimpleIdentitySet, EqHashMap, EqHashSet, SrcPos, Property}
18
18
import transform .{Recheck , PreRecheck , CapturedVars }
19
19
import Recheck .*
20
20
import scala .collection .mutable
21
- import CaptureSet .{withCaptureSetsExplained , CompareResult , CompareFailure , ExistentialSubsumesFailure }
21
+ import CaptureSet .{withCaptureSetsExplained , CompareResult , ExistentialSubsumesFailure }
22
22
import CCState .*
23
23
import StdNames .nme
24
24
import NameKinds .{DefaultGetterName , WildcardParamName , UniqueNameKind }
@@ -352,11 +352,12 @@ class CheckCaptures extends Recheck, SymTransformer:
352
352
assert(cs1.subCaptures(cs2).isOK, i " $cs1 is not a subset of $cs2" )
353
353
354
354
/** If `res` is not CompareResult.OK, report an error */
355
- def checkOK (res : CompareResult , prefix : => String , added : Capability | CaptureSet , target : CaptureSet , pos : SrcPos , provenance : => String = " " )(using Context ): Unit =
355
+ def checkOK (res : TypeComparer . CompareResult , prefix : => String , added : Capability | CaptureSet , target : CaptureSet , pos : SrcPos , provenance : => String = " " )(using Context ): Unit =
356
356
res match
357
- case res : CompareFailure =>
357
+ case TypeComparer .CompareResult .Fail (notes) =>
358
+ val ((res : CompareResult ) :: Nil , otherNotes) = notes.partition(_.isInstanceOf [CompareResult ]): @ unchecked
358
359
def msg (provisional : Boolean ) =
359
- def toAdd : String = errorNotes(res.errorNotes ).toAdd.mkString
360
+ def toAdd : String = errorNotes(otherNotes ).toAdd.mkString
360
361
def descr : String =
361
362
val d = res.blocking.description
362
363
if d.isEmpty then provenance else " "
@@ -377,18 +378,27 @@ class CheckCaptures extends Recheck, SymTransformer:
377
378
report.error(msg(provisional = false ), pos)
378
379
case _ =>
379
380
381
+ def convertResult (op : => CompareResult )(using Context ): TypeComparer .CompareResult =
382
+ TypeComparer .test:
383
+ op match
384
+ case res : TypeComparer .ErrorNote =>
385
+ TypeComparer .addErrorNote(res)
386
+ false
387
+ case CompareResult .OK =>
388
+ true
389
+
380
390
/** Check subcapturing `{elem} <: cs`, report error on failure */
381
391
def checkElem (elem : Capability , cs : CaptureSet , pos : SrcPos , provenance : => String = " " )(using Context ) =
382
392
checkOK(
383
- ccState.test (elem.singletonCaptureSet.subCaptures(cs)),
393
+ convertResult (elem.singletonCaptureSet.subCaptures(cs)),
384
394
i " $elem cannot be referenced here; it is not " ,
385
395
elem, cs, pos, provenance)
386
396
387
397
/** Check subcapturing `cs1 <: cs2`, report error on failure */
388
398
def checkSubset (cs1 : CaptureSet , cs2 : CaptureSet , pos : SrcPos ,
389
399
provenance : => String = " " , cs1description : String = " " )(using Context ) =
390
400
checkOK(
391
- ccState.test (cs1.subCaptures(cs2)),
401
+ convertResult (cs1.subCaptures(cs2)),
392
402
if cs1.elems.size == 1 then i " reference ${cs1.elems.nth(0 )}$cs1description is not "
393
403
else i " references $cs1$cs1description are not all " ,
394
404
cs1, cs2, pos, provenance)
@@ -1272,7 +1282,7 @@ class CheckCaptures extends Recheck, SymTransformer:
1272
1282
1273
1283
type BoxErrors = mutable.ListBuffer [Message ] | Null
1274
1284
1275
- private def errorNotes (notes : List [ErrorNote ])(using Context ): Addenda =
1285
+ private def errorNotes (notes : List [TypeComparer . ErrorNote ])(using Context ): Addenda =
1276
1286
if notes.isEmpty then NothingToAdd
1277
1287
else new Addenda :
1278
1288
override def toAdd (using Context ) = notes.map: note =>
@@ -1336,20 +1346,20 @@ class CheckCaptures extends Recheck, SymTransformer:
1336
1346
if actualBoxed eq actual then
1337
1347
// Only `addOuterRefs` when there is no box adaptation
1338
1348
expected1 = addOuterRefs(expected1, actual, tree.srcPos)
1339
- ccState.testOK(isCompatible(actualBoxed, expected1)) match
1340
- case CompareResult .OK =>
1341
- if debugSuccesses then tree match
1342
- case Ident (_) =>
1343
- println(i " SUCCESS $tree for $actual <:< $expected: \n ${TypeComparer .explained(_.isSubType(actualBoxed, expected1))}" )
1344
- case _ =>
1345
- actualBoxed
1346
- case fail : CompareFailure =>
1349
+ TypeComparer .test(isCompatible(actualBoxed, expected1)) match
1350
+ case TypeComparer .CompareResult .Fail (notes) =>
1347
1351
capt.println(i " conforms failed for ${tree}: $actual vs $expected" )
1348
1352
err.typeMismatch(tree.withType(actualBoxed), expected1,
1349
1353
addApproxAddenda(
1350
- addenda ++ errorNotes(fail.errorNotes ),
1354
+ addenda ++ errorNotes(notes ),
1351
1355
expected1))
1352
1356
actual
1357
+ case /* OK*/ _ =>
1358
+ if debugSuccesses then tree match
1359
+ case Ident (_) =>
1360
+ println(i " SUCCESS $tree for $actual <:< $expected: \n ${TypeComparer .explained(_.isSubType(actualBoxed, expected1))}" )
1361
+ case _ =>
1362
+ actualBoxed
1353
1363
end checkConformsExpr
1354
1364
1355
1365
/** Turn `expected` into a dependent function when `actual` is dependent. */
0 commit comments