Skip to content

Commit fdf60bb

Browse files
committed
SI-8960 Bring back the SerialVersionUID to anonymous function classes
In PR scala#1673 / 4267444, the annotation `SerialVersionId` was changed from a `StaticAnnotation` to `ClassFileAnnotation` in order to enforce annotation arguments to be constants. That was 2.11.0. The ID value in the AnnotationInfo moved from `args` to `assocs`, but the backend was not adjusted. This was fixed in PR scala#3711 / ecbc9d0 for 2.11.1. Unfortunately, the synthetic AnnotationInfo that is added to anonymous function classes still used the old constructor (`args` instead of `assocs`), so extracting the value failed, and no field was added to the classfile.
1 parent b556b2f commit fdf60bb

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/reflect/scala/reflect/internal/Definitions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,7 @@ trait Definitions extends api.StandardDefinitions {
11181118
lazy val ScalaInlineClass = requiredClass[scala.inline]
11191119
lazy val ScalaNoInlineClass = requiredClass[scala.noinline]
11201120
lazy val SerialVersionUIDAttr = requiredClass[scala.SerialVersionUID]
1121-
lazy val SerialVersionUIDAnnotation = AnnotationInfo(SerialVersionUIDAttr.tpe, List(Literal(Constant(0))), List())
1121+
lazy val SerialVersionUIDAnnotation = AnnotationInfo(SerialVersionUIDAttr.tpe, List(), List(nme.value -> LiteralAnnotArg(Constant(0))))
11221122
lazy val SpecializedClass = requiredClass[scala.specialized]
11231123
lazy val ThrowsClass = requiredClass[scala.throws[_]]
11241124
lazy val TransientAttr = requiredClass[scala.transient]

test/files/run/t8960.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
object Test extends App {
2+
val f = (new C).f
3+
assert(f.getClass.getDeclaredFields.exists(_.getName == "serialVersionUID"))
4+
}
5+
6+
class C {
7+
def f = () => ()
8+
}

0 commit comments

Comments
 (0)