Skip to content

Commit

Permalink
Do not copy annotations from a class to its synthetic companion object.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sjrd committed Sep 7, 2020
1 parent d11e137 commit b0f2868
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ object desugar {
val companionMods = mods
.withFlags((mods.flags & (AccessFlags | Final)).toCommonFlags)
.withMods(Nil)
.withAnnotations(Nil)

var defaultGetters: List[Tree] = Nil

Expand Down
33 changes: 19 additions & 14 deletions compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -491,21 +491,26 @@ object SymDenotations {

/** The name given in an `@alpha` annotation if one is present, `name` otherwise */
final def erasedName(using Context): Name =
getAnnotation(defn.AlphaAnnot) match {
case Some(ann) =>
ann.arguments match {
case Literal(Constant(str: String)) :: Nil =>
if (isType)
if (is(ModuleClass))
str.toTypeName.moduleClassName
else
str.toTypeName
def fromAnnot(ann: Annotation): Name =
ann.arguments match
case Literal(Constant(str: String)) :: Nil =>
if (isType)
if (is(ModuleClass))
str.toTypeName.moduleClassName
else
str.toTermName
case _ => name
}
case _ => name
}
str.toTypeName
else
str.toTermName
case _ => name
getAnnotation(defn.AlphaAnnot) match
case Some(ann) => fromAnnot(ann)
case _ =>
if isAllOf(ModuleClass | Synthetic) then
companionClass.getAnnotation(defn.AlphaAnnot) match
case Some(ann) => fromAnnot(ann)
case _ => name
else
name

// ----- Tests -------------------------------------------------

Expand Down

0 comments on commit b0f2868

Please sign in to comment.