@@ -542,16 +542,21 @@ class CheckCaptures extends Recheck, SymTransformer:
542
542
useInfos += ((tree, cs, curEnv))
543
543
end markFree
544
544
545
- /** If capability `c` refers to a parameter that is not @use declared, report an error.
545
+ /** If capability `c` refers to a parameter that is not implicitly or explicitly
546
+ * @use declared, report an error.
546
547
*/
547
548
def checkUseDeclared (c : Capability , pos : SrcPos )(using Context ): Unit =
548
549
c.paramPathRoot match
549
550
case ref : NamedType if ! ref.symbol.isUseParam =>
550
551
val what = if ref.isType then " Capture set parameter" else " Local reach capability"
551
- val owner = ref.symbol.owner
552
+ def mitigation =
553
+ if ccConfig.allowUse
554
+ then i " \n To allow this, the ${ref.symbol} should be declared with a @use annotation. "
555
+ else if ! ref.isType then i " \n You could try to abstract the capabilities referred to by $c in a capset variable. "
556
+ else " "
552
557
report.error(
553
- em """ $what $c leaks into capture scope ${owner.qualString(" of" )}.
554
- |To allow this, the ${ref.symbol} should be declared with a @use annotation """ , pos)
558
+ em " $what $c leaks into capture scope ${owner.qualString(" of" )}. $mitigation " ,
559
+ pos)
555
560
case _ =>
556
561
557
562
/** Include references captured by the called method in the current environment stack */
@@ -1751,7 +1756,7 @@ class CheckCaptures extends Recheck, SymTransformer:
1751
1756
1752
1757
override def checkInheritedTraitParameters : Boolean = false
1753
1758
1754
- /** Check that overrides don't change the @use or @consume status of their parameters */
1759
+ /** Check that overrides don't change the @use, @consume, or @reserve status of their parameters */
1755
1760
override def additionalChecks (member : Symbol , other : Symbol )(using Context ): Unit =
1756
1761
for
1757
1762
(params1, params2) <- member.rawParamss.lazyZip(other.rawParamss)
0 commit comments