Skip to content

ConstantAnnotation's aren't copied fully to module classes symbols #12430

Open
@dwijnand

Description

@dwijnand

reproduction steps

using Scala 2.13.6, comparing against 2.13.5,

scala> @deprecated("Use other", "v1.2.3") case class C()
class C

scala> :power
Already in power mode.

scala> val sym = typeOf[C].typeSymbol
                        ^
       warning: class C is deprecated (since v1.2.3): Use other
val sym: $r.intp.global.Symbol = class C

scala> val syms = List(sym, sym.companionModule.moduleClass)
val syms: List[$r.intp.global.Symbol] = List(class C, object C)

scala> val annots = syms.map(_.getAnnotation(definitions.DeprecatedAttr).get)
val annots: List[$r.intp.global.AnnotationInfo] = List(deprecated(message = "Use other", since = "v1.2.3"), deprecated)

scala> annots.map(_.args)
val res1: List[List[$r.intp.global.Tree]] = List(List(), List())

scala> annots.map(_.assocs)
val res2: List[List[($r.intp.global.Name, $r.intp.global.ClassfileAnnotArg)]] = List(List((message,"Use other"), (since,"v1.2.3")), List())

problem

The metadata "Use other" is only present on the case class annotation info, it's entirely missing on the module class's annotation info.

In 2.13.5, it's there:

scala> val annots = syms.map(_.getAnnotation(definitions.DeprecatedAttr).get)
val annots: List[$r.intp.global.AnnotationInfo] = List(deprecated("Use other", "v1.2.3"), deprecated("Use other", "v1.2.3"))

scala> annots.map(_.args)
val res0: List[List[$r.intp.global.Tree]] = List(List("Use other", "v1.2.3"), List("Use other", "v1.2.3"))

scala> annots.map(_.assocs)
val res1: List[List[($r.intp.global.Name, $r.intp.global.ClassfileAnnotArg)]] = List(List(), List())

The trigger is likely the change of @deprecated from extends scala.annotation.StaticAnnotation to extends scala.annotation.ConstantAnnotation in scala/scala#9336, but to me it seems to reveal a preexisting bug in how info is copied to the companion symbols and their annotations.

Spawns from lightbend/genjavadoc#286 / lightbend/genjavadoc#287.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions