@@ -157,14 +157,20 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
157157 checkInferredWellFormed(tree.tpt)
158158 if sym.is(Method ) then
159159 if sym.isSetter then
160- sym.copyAndKeepAnnotationsCarrying(thisPhase, Set (defn.SetterMetaAnnot ))
160+ sym.keepAnnotationsCarrying(thisPhase, Set (defn.SetterMetaAnnot ))
161+ if sym.isOneOf(GivenOrImplicit ) then
162+ val cls = sym.info.finalResultType.classSymbol
163+ if cls.isOneOf(GivenOrImplicit ) then
164+ sym.updateAnnotationsAfter(thisPhase,
165+ atPhase(thisPhase)(cls.annotationsCarrying(Set (defn.CompanionMethodMetaAnnot )))
166+ ++ sym.annotations)
161167 else
162168 if sym.is(Param ) then
163- sym.copyAndKeepAnnotationsCarrying (thisPhase, Set (defn.ParamMetaAnnot ), orNoneOf = defn.NonBeanMetaAnnots )
169+ sym.keepAnnotationsCarrying (thisPhase, Set (defn.ParamMetaAnnot ), orNoneOf = defn.NonBeanMetaAnnots )
164170 else if sym.is(ParamAccessor ) then
165- sym.copyAndKeepAnnotationsCarrying (thisPhase, Set (defn.GetterMetaAnnot , defn.FieldMetaAnnot ))
171+ sym.keepAnnotationsCarrying (thisPhase, Set (defn.GetterMetaAnnot , defn.FieldMetaAnnot ))
166172 else
167- sym.copyAndKeepAnnotationsCarrying (thisPhase, Set (defn.GetterMetaAnnot , defn.FieldMetaAnnot ), orNoneOf = defn.NonBeanMetaAnnots )
173+ sym.keepAnnotationsCarrying (thisPhase, Set (defn.GetterMetaAnnot , defn.FieldMetaAnnot ), orNoneOf = defn.NonBeanMetaAnnots )
168174 if sym.isScala2Macro && ! ctx.settings.XignoreScala2Macros .value then
169175 if ! sym.owner.unforcedDecls.exists(p => ! p.isScala2Macro && p.name == sym.name && p.signature == sym.signature)
170176 // Allow scala.reflect.materializeClassTag to be able to compile scala/reflect/package.scala
@@ -388,6 +394,8 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
388394 VarianceChecker .check(tree)
389395 annotateExperimental(sym)
390396 checkMacroAnnotation(sym)
397+ if sym.isOneOf(GivenOrImplicit ) then
398+ sym.keepAnnotationsCarrying(thisPhase, Set (defn.CompanionClassMetaAnnot ), orNoneOf = defn.MetaAnnots )
391399 tree.rhs match
392400 case impl : Template =>
393401 for parent <- impl.parents do
0 commit comments