@@ -417,7 +417,7 @@ object CaptureSet:
417
417
def isAlwaysEmpty = elems.isEmpty
418
418
419
419
def addNewElem (elem : CaptureRef , origin : CaptureSet )(using Context , VarState ): CompareResult =
420
- CompareResult .Fail (this )
420
+ CompareResult .Fail (this :: Nil )
421
421
422
422
def addDependent (cs : CaptureSet )(using Context , VarState ) = CompareResult .OK
423
423
@@ -505,7 +505,7 @@ object CaptureSet:
505
505
506
506
final def addNewElem (elem : CaptureRef , origin : CaptureSet )(using Context , VarState ): CompareResult =
507
507
if isConst || ! recordElemsState() then
508
- CompareResult .Fail (this ) // fail if variable is solved or given VarState is frozen
508
+ CompareResult .Fail (this :: Nil ) // fail if variable is solved or given VarState is frozen
509
509
else if ! levelOK(elem) then
510
510
val res = CompareResult .LevelError (this , elem)
511
511
if elem.isRootCapability then res
@@ -518,7 +518,7 @@ object CaptureSet:
518
518
// assert(id != 5 || elems.size != 3, this)
519
519
(CompareResult .OK /: deps) { (r, dep) =>
520
520
r.andAlso(dep.tryInclude(elem, this ))
521
- }
521
+ }.addToTrace( this )
522
522
523
523
private def levelOK (elem : CaptureRef )(using Context ): Boolean =
524
524
! levelLimit.exists
@@ -540,7 +540,7 @@ object CaptureSet:
540
540
deps += cs
541
541
CompareResult .OK
542
542
else
543
- CompareResult .Fail (this )
543
+ CompareResult .Fail (this :: Nil )
544
544
545
545
override def disallowRootCapability (handler : () => Context ?=> Unit )(using Context ): this .type =
546
546
rootAddedHandler = handler
@@ -684,7 +684,7 @@ object CaptureSet:
684
684
.andAlso {
685
685
if added.isConst then CompareResult .OK
686
686
else if added.asVar.recordDepsState() then { addAsDependentTo(added); CompareResult .OK }
687
- else CompareResult .Fail (this )
687
+ else CompareResult .Fail (this :: Nil )
688
688
}
689
689
.andAlso {
690
690
if (origin ne source) && (origin ne initial) && mapIsIdempotent then
@@ -701,7 +701,7 @@ object CaptureSet:
701
701
// we approximate types resulting from such maps by returning a possible super type
702
702
// from the actual type. But this is neither sound nor complete.
703
703
report.warning(em " trying to add elems ${CaptureSet (newElems)} from unrecognized source $origin of mapped set $this$whereCreated" )
704
- CompareResult .Fail (this )
704
+ CompareResult .Fail (this :: Nil )
705
705
else
706
706
CompareResult .OK
707
707
}
@@ -767,7 +767,7 @@ object CaptureSet:
767
767
super .addNewElems(newElems, origin)
768
768
.andAlso {
769
769
if filtered.size == newElems.size then source.tryInclude(newElems, this )
770
- else CompareResult .Fail (this )
770
+ else CompareResult .Fail (this :: Nil )
771
771
}
772
772
773
773
override def computeApprox (origin : CaptureSet )(using Context ): CaptureSet =
@@ -866,14 +866,16 @@ object CaptureSet:
866
866
867
867
enum CompareResult extends Showable :
868
868
case OK
869
- case Fail (cs : CaptureSet )
869
+ case Fail (trace : List [ CaptureSet ] )
870
870
case LevelError (cs : CaptureSet , elem : CaptureRef )
871
871
872
872
override def toText (printer : Printer ): Text =
873
873
inContext(printer.printerContext):
874
874
this match
875
875
case OK => Str (" OK" )
876
- case Fail (blocking : CaptureSet ) => blocking.show
876
+ case Fail (trace) =>
877
+ if ctx.settings.YccDebug .value then printer.toText(trace, " , " )
878
+ else blocking.show
877
879
case LevelError (cs : CaptureSet , elem : CaptureRef ) =>
878
880
Str (i " ( $elem at wrong level for $cs in ${cs.levelLimit}) " )
879
881
@@ -882,7 +884,7 @@ object CaptureSet:
882
884
883
885
/** If not isOK, the blocking capture set */
884
886
def blocking : CaptureSet = (this : @ unchecked) match
885
- case Fail (cs) => cs
887
+ case Fail (cs) => cs.last
886
888
case LevelError (cs, _) => cs
887
889
888
890
/** Optionally, this result if it is a level error */
@@ -899,6 +901,10 @@ object CaptureSet:
899
901
val alt = op
900
902
if alt.isOK then alt
901
903
else this
904
+
905
+ inline def addToTrace (cs : CaptureSet ) = this match
906
+ case Fail (trace) => Fail (cs :: trace)
907
+ case _ => this
902
908
end CompareResult
903
909
904
910
/** A VarState serves as a snapshot mechanism that can undo
0 commit comments