Skip to content

Commit 3c36c3c

Browse files
committed
Keep @use and @consume on parameter accessors
1 parent 4ec6751 commit 3c36c3c

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,7 @@ class Definitions {
11071107
@tu lazy val NonBeanMetaAnnots: Set[Symbol] =
11081108
Set(FieldMetaAnnot, GetterMetaAnnot, ParamMetaAnnot, SetterMetaAnnot, CompanionClassMetaAnnot, CompanionMethodMetaAnnot)
11091109
@tu lazy val NonBeanParamAccessorAnnots: Set[Symbol] =
1110-
Set(PublicInBinaryAnnot)
1110+
Set(PublicInBinaryAnnot, UseAnnot, ConsumeAnnot)
11111111
@tu lazy val MetaAnnots: Set[Symbol] =
11121112
NonBeanMetaAnnots + BeanGetterMetaAnnot + BeanSetterMetaAnnot
11131113

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,16 @@ object SymDenotations {
252252
final def filterAnnotations(p: Annotation => Boolean)(using Context): Unit =
253253
annotations = annotations.filterConserve(p)
254254

255-
def annotationsCarrying(meta: Set[Symbol], orNoneOf: Set[Symbol] = Set.empty)(using Context): List[Annotation] =
256-
annotations.filterConserve(_.hasOneOfMetaAnnotation(meta, orNoneOf = orNoneOf))
257-
258-
def keepAnnotationsCarrying(phase: DenotTransformer, meta: Set[Symbol], orNoneOf: Set[Symbol] = Set.empty)(using Context): Unit =
259-
updateAnnotationsAfter(phase, annotationsCarrying(meta, orNoneOf = orNoneOf))
255+
def annotationsCarrying(meta: Set[Symbol],
256+
orNoneOf: Set[Symbol] = Set.empty,
257+
andAlso: Set[Symbol] = Set.empty)(using Context): List[Annotation] =
258+
annotations.filterConserve: annot =>
259+
annot.hasOneOfMetaAnnotation(meta, orNoneOf = orNoneOf)
260+
|| andAlso.contains(annot.symbol)
261+
262+
def keepAnnotationsCarrying(phase: DenotTransformer, meta: Set[Symbol],
263+
orNoneOf: Set[Symbol] = Set.empty, andAlso: Set[Symbol] = Set.empty)(using Context): Unit =
264+
updateAnnotationsAfter(phase, annotationsCarrying(meta, orNoneOf, andAlso))
260265

261266
def updateAnnotationsAfter(phase: DenotTransformer, annots: List[Annotation])(using Context): Unit =
262267
if annots ne annotations then

compiler/src/dotty/tools/dotc/transform/PostTyper.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,8 @@ class PostTyper extends MacroTransform with InfoTransformer { thisPhase =>
255255
sym.keepAnnotationsCarrying(thisPhase, Set(defn.ParamMetaAnnot), orNoneOf = defn.NonBeanMetaAnnots)
256256
unusing.foreach(sym.addAnnotation)
257257
else if sym.is(ParamAccessor) then
258-
// @publicInBinary is not a meta-annotation and therefore not kept by `keepAnnotationsCarrying`
259-
val publicInBinaryAnnotOpt = sym.getAnnotation(defn.PublicInBinaryAnnot)
260-
sym.keepAnnotationsCarrying(thisPhase, Set(defn.GetterMetaAnnot, defn.FieldMetaAnnot))
261-
for publicInBinaryAnnot <- publicInBinaryAnnotOpt do sym.addAnnotation(publicInBinaryAnnot)
258+
sym.keepAnnotationsCarrying(thisPhase, Set(defn.GetterMetaAnnot, defn.FieldMetaAnnot),
259+
andAlso = defn.NonBeanParamAccessorAnnots)
262260
else
263261
sym.keepAnnotationsCarrying(thisPhase, Set(defn.GetterMetaAnnot, defn.FieldMetaAnnot), orNoneOf = defn.NonBeanMetaAnnots)
264262
if sym.isScala2Macro && !ctx.settings.XignoreScala2Macros.value &&
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import language.experimental.captureChecking
2+
import caps.use
3+
4+
/*class Test:
5+
class Runner(ops: List[() => Unit]):
6+
def execute: Unit = ops.foreach(f => f()) // error
7+
8+
def Runner2(ops: List[() => Unit]) =
9+
() => ops.foreach(f => f()) // error
10+
*/
11+
12+
class Test2:
13+
class Runner(@use ops: List[() => Unit]):
14+
def execute: Unit = ops.foreach(f => f()) //ok
15+
16+
private def Runner2(@use ops: List[() => Unit]) =
17+
() => ops.foreach(f => f()) // ok

0 commit comments

Comments
 (0)