@@ -18,7 +18,7 @@ import util.{SimpleIdentitySet, EqHashMap, EqHashSet, SrcPos, Property}
1818import transform .{Recheck , PreRecheck , CapturedVars }
1919import Recheck .*
2020import scala .collection .mutable
21- import CaptureSet .{withCaptureSetsExplained , CompareResult , CompareFailure , ExistentialSubsumesFailure }
21+ import CaptureSet .{withCaptureSetsExplained , CompareResult , ExistentialSubsumesFailure }
2222import CCState .*
2323import StdNames .nme
2424import NameKinds .{DefaultGetterName , WildcardParamName , UniqueNameKind }
@@ -352,11 +352,12 @@ class CheckCaptures extends Recheck, SymTransformer:
352352 assert(cs1.subCaptures(cs2).isOK, i " $cs1 is not a subset of $cs2" )
353353
354354 /** 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 =
356356 res match
357- case res : CompareFailure =>
357+ case TypeComparer .CompareResult .Fail (notes) =>
358+ val ((res : CompareResult ) :: Nil , otherNotes) = notes.partition(_.isInstanceOf [CompareResult ]): @ unchecked
358359 def msg (provisional : Boolean ) =
359- def toAdd : String = errorNotes(res.errorNotes ).toAdd.mkString
360+ def toAdd : String = errorNotes(otherNotes ).toAdd.mkString
360361 def descr : String =
361362 val d = res.blocking.description
362363 if d.isEmpty then provenance else " "
@@ -377,18 +378,27 @@ class CheckCaptures extends Recheck, SymTransformer:
377378 report.error(msg(provisional = false ), pos)
378379 case _ =>
379380
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+
380390 /** Check subcapturing `{elem} <: cs`, report error on failure */
381391 def checkElem (elem : Capability , cs : CaptureSet , pos : SrcPos , provenance : => String = " " )(using Context ) =
382392 checkOK(
383- ccState.test (elem.singletonCaptureSet.subCaptures(cs)),
393+ convertResult (elem.singletonCaptureSet.subCaptures(cs)),
384394 i " $elem cannot be referenced here; it is not " ,
385395 elem, cs, pos, provenance)
386396
387397 /** Check subcapturing `cs1 <: cs2`, report error on failure */
388398 def checkSubset (cs1 : CaptureSet , cs2 : CaptureSet , pos : SrcPos ,
389399 provenance : => String = " " , cs1description : String = " " )(using Context ) =
390400 checkOK(
391- ccState.test (cs1.subCaptures(cs2)),
401+ convertResult (cs1.subCaptures(cs2)),
392402 if cs1.elems.size == 1 then i " reference ${cs1.elems.nth(0 )}$cs1description is not "
393403 else i " references $cs1$cs1description are not all " ,
394404 cs1, cs2, pos, provenance)
@@ -1272,7 +1282,7 @@ class CheckCaptures extends Recheck, SymTransformer:
12721282
12731283 type BoxErrors = mutable.ListBuffer [Message ] | Null
12741284
1275- private def errorNotes (notes : List [ErrorNote ])(using Context ): Addenda =
1285+ private def errorNotes (notes : List [TypeComparer . ErrorNote ])(using Context ): Addenda =
12761286 if notes.isEmpty then NothingToAdd
12771287 else new Addenda :
12781288 override def toAdd (using Context ) = notes.map: note =>
@@ -1336,20 +1346,20 @@ class CheckCaptures extends Recheck, SymTransformer:
13361346 if actualBoxed eq actual then
13371347 // Only `addOuterRefs` when there is no box adaptation
13381348 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) =>
13471351 capt.println(i " conforms failed for ${tree}: $actual vs $expected" )
13481352 err.typeMismatch(tree.withType(actualBoxed), expected1,
13491353 addApproxAddenda(
1350- addenda ++ errorNotes(fail.errorNotes ),
1354+ addenda ++ errorNotes(notes ),
13511355 expected1))
13521356 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
13531363 end checkConformsExpr
13541364
13551365 /** Turn `expected` into a dependent function when `actual` is dependent. */
0 commit comments