@@ -117,7 +117,9 @@ object SepCheck:
117117 if i < size then locs(i) else null
118118
119119 def clashing (ref : Capability )(using Context ): SrcPos | Null =
120- val refPeaks = ref.directPeaks
120+ val refPeaks = ref match
121+ case ReadOnly (_) => ref.directPeaks // TODO: this should be removed once the classifier zoo is revised
122+ case _ => ref.stripRestricted.directPeaks
121123 if ! directPeaks.sharedPeaks(refPeaks).isEmpty then
122124 var i = 0
123125 while i < size && refs(i).directPeaks.sharedPeaks(refPeaks).isEmpty do
@@ -658,8 +660,11 @@ class SepCheck(checker: CheckCaptures.CheckerAPI) extends tpd.TreeTraverser:
658660 sepUseError(tree, null , used, defsShadow)
659661 end if
660662
663+ // println(i"consumed so far: ${consumed.show}")
664+ // println(i"used at $tree: $used")
661665 for ref <- used do
662666 val pos = consumed.clashing(ref)
667+ // println(i"checking ref $ref, clashing at $pos")
663668 if pos != null then
664669 // Check if this reference should be exempted because consume fields along
665670 // the path own the consumed capabilities.
@@ -669,8 +674,10 @@ class SepCheck(checker: CheckCaptures.CheckerAPI) extends tpd.TreeTraverser:
669674 // We need to check both the capability and its reach, since consumed might store the reach version.
670675 val shouldExempt = pathConsumed.exists:
671676 case _ : RootCapability => false
672- case c : DerivedCapability => consumed.get(c.underlying) == pos
673- case c => consumed.get(c) == pos
677+ case c : DerivedCapability if ! c.isReadOnly => consumed.get(c.underlying) == pos
678+ case c => consumed.get(c) == pos || consumed.get(c.reach) == pos // TODO this is subtle
679+
680+ // println(i"path consumed for $ref: $pathConsumed, shouldExempt = $shouldExempt")
674681
675682 if ! shouldExempt then
676683 consumeError(ref, pos, tree.srcPos)
0 commit comments