diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 92dd368ac5..f503a797bb 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -1330,7 +1330,9 @@ trait Typers { self: Analyzer => val value = stat.symbol val allAnnots = value.annotations if (!isDeferred) - value.setAnnotations(memberAnnots(allAnnots, FieldTargetClass)) + // keepClean: by default annotations go to the field, except if the field is + // generated for a class parameter (PARAMACCESSOR). + value.setAnnotations(memberAnnots(allAnnots, FieldTargetClass, keepClean = !mods.hasFlag(PARAMACCESSOR))) val getter = if (isDeferred) value else value.getter(value.owner) assert(getter != NoSymbol, stat) @@ -1410,10 +1412,12 @@ trait Typers { self: Analyzer => List(stat) } - /** The annotations amongst `annots` that should go on a member of class - * `memberClass` (field, getter, setter, beanGetter, beanSetter, param) + /** + * The annotations amongst `annots` that should go on a member of class + * `memberClass` (field, getter, setter, beanGetter, beanSetter, param) + * If 'keepClean' is true, annotations without any meta-annotation are kept */ - protected def memberAnnots(annots: List[AnnotationInfo], memberClass: Symbol) = { + protected def memberAnnots(annots: List[AnnotationInfo], memberClass: Symbol, keepClean: Boolean = false) = { def hasMatching(metaAnnots: List[AnnotationInfo], orElse: => Boolean) = { // either one of the meta-annotations matches the `memberClass` @@ -1430,7 +1434,7 @@ trait Typers { self: Analyzer => // there was no meta-annotation on `ann`. Look if the class annotations of // `ann` has a `target` annotation, otherwise put `ann` only on fields. def noMetaAnnot(ann: AnnotationInfo) = { - hasMatching(ann.atp.typeSymbol.annotations, memberClass == FieldTargetClass) + hasMatching(ann.atp.typeSymbol.annotations, keepClean) } annots.filter(ann => ann.atp match { @@ -1702,7 +1706,7 @@ trait Typers { self: Analyzer => for (vparams <- ddef.vparamss; vd <- vparams) { if (vd hasFlag PARAMACCESSOR) { val sym = vd.symbol - sym.setAnnotations(memberAnnots(sym.annotations, ParamTargetClass)) + sym.setAnnotations(memberAnnots(sym.annotations, ParamTargetClass, keepClean = true)) } } } |