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