@@ -147,6 +147,14 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
147147 case tree : ValOrDefDef if ! tree.symbol.is(Synthetic ) =>
148148 checkInferredWellFormed(tree.tpt)
149149 val sym = tree.symbol
150+ if sym.is(Method ) then
151+ if sym.isSetter then
152+ removeUnwantedAnnotations(sym, defn.SetterMetaAnnot , NoSymbol , keepIfNoRelevantAnnot = false )
153+ else
154+ if sym.is(Param ) then
155+ removeUnwantedAnnotations(sym, defn.ParamMetaAnnot , NoSymbol , keepIfNoRelevantAnnot = true )
156+ else
157+ removeUnwantedAnnotations(sym, defn.GetterMetaAnnot , defn.FieldMetaAnnot , keepIfNoRelevantAnnot = ! sym.is(ParamAccessor ))
150158 if sym.isScala2Macro && ! ctx.settings.XignoreScala2Macros .value then
151159 if ! sym.owner.unforcedDecls.exists(p => ! p.isScala2Macro && p.name == sym.name && p.signature == sym.signature)
152160 // Allow scala.reflect.materializeClassTag to be able to compile scala/reflect/package.scala
@@ -168,6 +176,18 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
168176 => Checking .checkAppliedTypesIn(tree)
169177 case _ =>
170178
179+ private def removeUnwantedAnnotations (sym : Symbol , metaAnnotSym : Symbol ,
180+ metaAnnotSymBackup : Symbol , keepIfNoRelevantAnnot : Boolean )(using Context ): Unit =
181+ def shouldKeep (annot : Annotation ): Boolean =
182+ val annotSym = annot.symbol
183+ annotSym.hasAnnotation(metaAnnotSym)
184+ || annotSym.hasAnnotation(metaAnnotSymBackup)
185+ || (keepIfNoRelevantAnnot && {
186+ ! annotSym.annotations.exists(metaAnnot => defn.FieldAccessorMetaAnnots .contains(metaAnnot.symbol))
187+ })
188+ if sym.annotations.nonEmpty then
189+ sym.filterAnnotations(shouldKeep(_))
190+
171191 private def transformSelect (tree : Select , targs : List [Tree ])(using Context ): Tree = {
172192 val qual = tree.qualifier
173193 qual.symbol.moduleClass.denot match {
0 commit comments