diff options
author | Adriaan Moors <adriaan@lightbend.com> | 2016-12-05 10:45:09 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-05 10:45:09 +0100 |
commit | 2787b47396013a44072fa7321482103b66fbccd3 (patch) | |
tree | a047943567adc5bb10182d9c0c27034f73f23e29 /src/compiler/scala/tools/nsc/typechecker/Namers.scala | |
parent | ee1c02b374a4b8a053e9a8b14af5e205afa67e14 (diff) | |
parent | 7bf8ffa155ba66311a904c7eeaca79a70aa7e6f7 (diff) | |
download | scala-2787b47396013a44072fa7321482103b66fbccd3.tar.gz scala-2787b47396013a44072fa7321482103b66fbccd3.tar.bz2 scala-2787b47396013a44072fa7321482103b66fbccd3.zip |
Merge pull request #5570 from adriaanm/t10075
SI-10075 propagate annotations to lazy val's underlying field
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/Namers.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Namers.scala | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index 7ffc6c6b48..b445bc5837 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -902,9 +902,10 @@ trait Namers extends MethodSynthesis { // Annotations on ValDefs can be targeted towards the following: field, getter, setter, beanGetter, beanSetter, param. // The defaults are: // - (`val`-, `var`- or plain) constructor parameter annotations end up on the parameter, not on any other entity. - // - val/var member annotations solely end up on the underlying field, except in traits (@since 2.12), + // - val/var member annotations solely end up on the underlying field, except in traits and for all lazy vals (@since 2.12), // where there is no field, and the getter thus holds annotations targeting both getter & field. - // As soon as there is a field/getter (in subclasses mixing in the trait), we triage the annotations. + // As soon as there is a field/getter (in subclasses mixing in the trait, or after expanding the lazy val during the fields phase), + // we triage the annotations. // // TODO: these defaults can be surprising for annotations not meant for accessors/fields -- should we revisit? // (In order to have `@foo val X` result in the X getter being annotated with `@foo`, foo needs to be meta-annotated with @getter) @@ -918,15 +919,17 @@ trait Namers extends MethodSynthesis { BeanPropertyAnnotationLimitationError(tree) } + val canTriageAnnotations = isSetter || !fields.getterTreeAnnotationsTargetFieldAndGetter(owner, mods) + def filterAccessorAnnotations: AnnotationInfo => Boolean = - if (isSetter || !owner.isTrait) + if (canTriageAnnotations) annotationFilter(if (isSetter) SetterTargetClass else GetterTargetClass, defaultRetention = false) else (ann => annotationFilter(FieldTargetClass, defaultRetention = true)(ann) || annotationFilter(GetterTargetClass, defaultRetention = true)(ann)) def filterBeanAccessorAnnotations: AnnotationInfo => Boolean = - if (isSetter || !owner.isTrait) + if (canTriageAnnotations) annotationFilter(if (isSetter) BeanSetterTargetClass else BeanGetterTargetClass, defaultRetention = false) else (ann => annotationFilter(FieldTargetClass, defaultRetention = true)(ann) || |