@@ -567,24 +567,16 @@ class SepCheck(checker: CheckCaptures.CheckerAPI) extends tpd.TreeTraverser:
567
567
if pos != null then consumeError(ref, pos, tree.srcPos)
568
568
end checkUse
569
569
570
- /** If `tp` denotes some version of a singleton type `x.type` the set `{x}`
570
+ /** If `tp` denotes some version of a singleton capture ref `x.type` the set `{x, x* }`
571
571
* otherwise the empty set.
572
572
*/
573
- def explicitRefs (tp : Type ): Refs = tp match
574
- case tp : (TermRef | ThisType ) => SimpleIdentitySet (tp)
573
+ def explicitRefs (tp : Type )( using Context ) : Refs = tp match
574
+ case tp : (TermRef | ThisType ) if tp.isTrackableRef => SimpleIdentitySet (tp, tp.reach )
575
575
case AnnotatedType (parent, _) => explicitRefs(parent)
576
576
case AndType (tp1, tp2) => explicitRefs(tp1) ++ explicitRefs(tp2)
577
577
case OrType (tp1, tp2) => explicitRefs(tp1) ** explicitRefs(tp2)
578
578
case _ => emptyRefs
579
579
580
- /** Deduct some elements from `refs` according to the role of the checked type `tpe`:
581
- * - If the the type apears as a (result-) type of a definition of `x`, deduct
582
- * `x` and `x*`.
583
- * - If `tpe` is morally a singleton type deduct it as well.
584
- */
585
- def prune (refs : Refs , tpe : Type , role : TypeRole )(using Context ): Refs =
586
- refs.deductSymFootprint(role.dclSym).deduct(explicitRefs(tpe))
587
-
588
580
/** Check validity of consumed references `refsToCheck`. The references are consumed
589
581
* because they are hidden in a Fresh result type or they are referred
590
582
* to in an argument to a @consume parameter or in a prefix of a @consume method --
@@ -611,7 +603,7 @@ class SepCheck(checker: CheckCaptures.CheckerAPI) extends tpd.TreeTraverser:
611
603
def checkConsumedRefs (refsToCheck : Refs , tpe : Type , role : TypeRole , descr : => String , pos : SrcPos )(using Context ) =
612
604
val badParams = mutable.ListBuffer [Symbol ]()
613
605
def currentOwner = role.dclSym.orElse(ctx.owner)
614
- for hiddenRef <- prune( refsToCheck, tpe, role) do
606
+ for hiddenRef <- refsToCheck.deductSymRefs( role.dclSym).deduct(explicitRefs(tpe) ) do
615
607
if ! hiddenRef.derivesFromSharedCapability then
616
608
hiddenRef.pathRoot match
617
609
case ref : TermRef =>
@@ -662,8 +654,17 @@ class SepCheck(checker: CheckCaptures.CheckerAPI) extends tpd.TreeTraverser:
662
654
*/
663
655
def checkType (tpe : Type , pos : SrcPos , role : TypeRole )(using Context ): Unit =
664
656
657
+ /** Deduct some elements from `refs` according to the role of the checked type `tpe`:
658
+ * - If the the type apears as a (result-) type of a definition of `x`, deduct
659
+ * `x` and `x*`.
660
+ * - If the checked type (or, for arguments, the actual type of the argument)
661
+ * is morally a singleton type `y.type` deduct `y` and `y*` as well.
662
+ */
665
663
extension (refs : Refs ) def pruned =
666
- refs.deductSymRefs(role.dclSym).deduct(explicitRefs(tpe))
664
+ val deductedType = role match
665
+ case TypeRole .Argument (arg) => arg.tpe
666
+ case _ => tpe
667
+ refs.deductSymRefs(role.dclSym).deduct(explicitRefs(deductedType))
667
668
668
669
def sepTypeError (parts : List [Type ], genPart : Type , otherPart : Type ): Unit =
669
670
val captured = genPart.deepCaptureSet.elems
0 commit comments