@@ -175,7 +175,7 @@ sealed abstract class CaptureSet extends Showable:
175
175
176
176
protected def addIfHiddenOrFail (elem : Capability )(using ctx : Context , vs : VarState ): Boolean =
177
177
elems.exists(_.maxSubsumes(elem, canAddHidden = true ))
178
- || failWith(IncludeFailure (this :: Nil ))
178
+ || failWith(IncludeFailure (this , elem ))
179
179
180
180
/** If this is a variable, add `cs` as a dependent set */
181
181
protected def addDependent (cs : CaptureSet )(using Context , VarState ): Boolean
@@ -604,7 +604,7 @@ object CaptureSet:
604
604
if isConst || ! recordElemsState() then // Fail if variable is solved or given VarState is frozen
605
605
addIfHiddenOrFail(elem)
606
606
else if ! levelOK(elem) then
607
- failWith(LevelError (this , elem)) // or `elem` is not visible at the level of the set.
607
+ failWith(IncludeFailure (this , elem, levelError = true )) // or `elem` is not visible at the level of the set.
608
608
else
609
609
// id == 108 then assert(false, i"trying to add $elem to $this")
610
610
assert(elem.isWellformed, elem)
@@ -622,7 +622,7 @@ object CaptureSet:
622
622
if ! res then
623
623
elems -= elem
624
624
TypeComparer .updateErrorNotes:
625
- case IncludeFailure (trace) => IncludeFailure (this :: trace )
625
+ case note : IncludeFailure => note.addToTrace (this )
626
626
res
627
627
628
628
private def isPartOf (binder : Type )(using Context ): Boolean =
@@ -667,13 +667,10 @@ object CaptureSet:
667
667
true
668
668
669
669
def addDependent (cs : CaptureSet )(using Context , VarState ): Boolean =
670
- if (cs eq this ) || cs.isUniversal || isConst then
671
- true
672
- else if recordDepsState() then
673
- deps += cs
674
- true
675
- else
676
- failWith(IncludeFailure (this :: Nil ))
670
+ (cs eq this )
671
+ || cs.isUniversal
672
+ || isConst
673
+ || recordDepsState() && { deps += cs; true }
677
674
678
675
override def disallowRootCapability (upto : Symbol )(handler : () => Context ?=> Unit )(using Context ): this .type =
679
676
rootLimit = upto
@@ -871,7 +868,7 @@ object CaptureSet:
871
868
// Filtered elements have to be back-propagated to source.
872
869
// Elements that don't satisfy `p` are not allowed.
873
870
if p(elem) then source.tryInclude(elem, this )
874
- else failWith(IncludeFailure (this :: Nil ))
871
+ else failWith(IncludeFailure (this , elem ))
875
872
876
873
override def computeApprox (origin : CaptureSet )(using Context ): CaptureSet =
877
874
if source eq origin then
@@ -1079,25 +1076,24 @@ object CaptureSet:
1079
1076
*/
1080
1077
case class ExistentialSubsumesFailure (val ex : ResultCap , val other : Capability ) extends ErrorNote
1081
1078
1082
- sealed abstract class CompareFailure extends ErrorNote , Showable :
1083
- override def kind = classOf [CompareFailure ]
1079
+ case class IncludeFailure (cs : CaptureSet , elem : Capability , levelError : Boolean = false ) extends ErrorNote , Showable :
1080
+ private var myTrace : List [CaptureSet ] = cs :: Nil
1081
+
1082
+ def trace : List [CaptureSet ] = myTrace
1083
+ def addToTrace (cs1 : CaptureSet ) =
1084
+ val res = IncludeFailure (cs, elem, levelError)
1085
+ res.myTrace = cs1 :: this .myTrace
1086
+ res
1087
+
1084
1088
override def toText (printer : Printer ): Text =
1085
1089
inContext(printer.printerContext):
1086
- this match
1087
- case IncludeFailure (trace) =>
1088
- if ctx.settings.YccDebug .value then printer.toText(trace, " , " )
1089
- else blocking.show
1090
- case LevelError (cs : CaptureSet , elem : Capability ) =>
1091
- Str (i " ( $elem at wrong level for $cs at level ${cs.level.toString}) " )
1092
-
1093
- /** If not isOK, the blocking capture set */
1094
- def blocking : CaptureSet = (this : @ unchecked) match
1095
- case IncludeFailure (cs) => cs.last
1096
- case LevelError (cs, _) => cs
1097
- end CompareFailure
1098
-
1099
- case class IncludeFailure (trace : List [CaptureSet ]) extends CompareFailure
1100
- case class LevelError (cs : CaptureSet , elem : Capability ) extends CompareFailure
1090
+ if levelError then
1091
+ i " ( $elem at wrong level for $cs at level ${cs.level.toString}) "
1092
+ else
1093
+ if ctx.settings.YccDebug .value
1094
+ then i " $elem cannot be included in $trace"
1095
+ else i " $elem cannot be included in $cs"
1096
+ end IncludeFailure
1101
1097
1102
1098
/** A VarState serves as a snapshot mechanism that can undo
1103
1099
* additions of elements or super sets if an operation fails
0 commit comments