Skip to content

Commit c9b8e7a

Browse files
committed
Do not copy annotations from a class to its synthetic companion object.
Normally, annotations applied to a class have no business being replicated on a synthetic companion object. One exception was the `@alpha` method, which is supposed to apply as well. Instead of trying to identify those annotations without the symbols during `Desugar`, we change `erasedName` to go look on the companion class of synthetic module classes.
1 parent c104e9b commit c9b8e7a

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ object desugar {
365365
val companionMods = mods
366366
.withFlags((mods.flags & (AccessFlags | Final)).toCommonFlags)
367367
.withMods(Nil)
368+
.withAnnotations(Nil)
368369

369370
var defaultGetters: List[Tree] = Nil
370371

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,10 @@ object SymDenotations {
491491

492492
/** The name given in an `@alpha` annotation if one is present, `name` otherwise */
493493
final def erasedName(using Context): Name =
494-
getAnnotation(defn.AlphaAnnot) match {
494+
val alphaAnnot =
495+
if isAllOf(ModuleClass | Synthetic) then companionClass.getAnnotation(defn.AlphaAnnot)
496+
else getAnnotation(defn.AlphaAnnot)
497+
alphaAnnot match {
495498
case Some(ann) =>
496499
ann.arguments match {
497500
case Literal(Constant(str: String)) :: Nil =>

0 commit comments

Comments
 (0)