Skip to content

Commit ced9e16

Browse files
committed
Merge pull request scala#4093 from lrytz/t8960
SI-8960 Bring back the SerialVersionUID to anonymous function classes
2 parents cd50464 + 21a44fe commit ced9e16

File tree

6 files changed

+72
-6
lines changed

6 files changed

+72
-6
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/delambdafy_uncurry_byname_inline.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package <empty> {
77
};
88
def bar(x: () => Int): Int = x.apply();
99
def foo(): Int = Foo.this.bar({
10-
@SerialVersionUID(0) final <synthetic> class $anonfun extends scala.runtime.AbstractFunction0[Int] with Serializable {
10+
@SerialVersionUID(value = 0) final <synthetic> class $anonfun extends scala.runtime.AbstractFunction0[Int] with Serializable {
1111
def <init>(): <$anon: () => Int> = {
1212
$anonfun.super.<init>();
1313
()

test/files/run/delambdafy_uncurry_inline.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package <empty> {
77
};
88
def bar(): Unit = {
99
val f: Int => Int = {
10-
@SerialVersionUID(0) final <synthetic> class $anonfun extends scala.runtime.AbstractFunction1[Int,Int] with Serializable {
10+
@SerialVersionUID(value = 0) final <synthetic> class $anonfun extends scala.runtime.AbstractFunction1[Int,Int] with Serializable {
1111
def <init>(): <$anon: Int => Int> = {
1212
$anonfun.super.<init>();
1313
()

test/files/run/t6028.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ package <empty> {
2424
(new <$anon: Function0>(T.this, tryyParam, tryyLocal): Function0)
2525
}
2626
};
27-
@SerialVersionUID(0) final <synthetic> class $anonfun$foo$1 extends scala.runtime.AbstractFunction0$mcI$sp with Serializable {
27+
@SerialVersionUID(value = 0) final <synthetic> class $anonfun$foo$1 extends scala.runtime.AbstractFunction0$mcI$sp with Serializable {
2828
def <init>($outer: T, methodParam$1: Int, methodLocal$1: Int): <$anon: Function0> = {
2929
$anonfun$foo$1.super.<init>();
3030
()
@@ -60,7 +60,7 @@ package <empty> {
6060
};
6161
scala.this.Predef.print(scala.Int.box(barParam$1))
6262
};
63-
@SerialVersionUID(0) final <synthetic> class $anonfun$tryy$1 extends scala.runtime.AbstractFunction0$mcV$sp with Serializable {
63+
@SerialVersionUID(value = 0) final <synthetic> class $anonfun$tryy$1 extends scala.runtime.AbstractFunction0$mcV$sp with Serializable {
6464
def <init>($outer: T, tryyParam$1: Int, tryyLocal$1: runtime.IntRef): <$anon: Function0> = {
6565
$anonfun$tryy$1.super.<init>();
6666
()

test/files/run/t6555.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package <empty> {
66
()
77
};
88
private[this] val f: Int => Int = {
9-
@SerialVersionUID(0) final <synthetic> class $anonfun extends scala.runtime.AbstractFunction1$mcII$sp with Serializable {
9+
@SerialVersionUID(value = 0) final <synthetic> class $anonfun extends scala.runtime.AbstractFunction1$mcII$sp with Serializable {
1010
def <init>(): <$anon: Int => Int> = {
1111
$anonfun.super.<init>();
1212
()

test/files/run/t8960.scala

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
object Test extends App {
2+
def test(o: AnyRef, sp: Boolean = false) = {
3+
if (sp) assert(o.getClass.getSuperclass.getName contains "$sp")
4+
val Some(f) = o.getClass.getDeclaredFields.find(_.getName == "serialVersionUID")
5+
assert(f.getLong(null) == 0l)
6+
}
7+
8+
test(() => (), sp = true)
9+
test(() => 1, sp = true)
10+
test(() => "")
11+
12+
test((x: Int) => x, sp = true)
13+
test((x: Boolean) => x)
14+
test((x: Int) => "")
15+
16+
test((x1: Int, x2: Int) => 0d, sp = true)
17+
test((x1: Int, x2: AnyRef) => 0d)
18+
test((x1: Any, x2: Any) => x1)
19+
20+
// scala> println((for (i <- 3 to 22) yield (for (j <- 1 to i) yield s"x$j: Int").mkString(" test((", ", ", ") => x1)")).mkString("\n"))
21+
22+
test((x1: Int, x2: Int, x3: Int) => x1)
23+
test((x1: Int, x2: Int, x3: Int, x4: Int) => x1)
24+
test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int) => x1)
25+
test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int) => x1)
26+
test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int) => x1)
27+
test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int) => x1)
28+
test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int) => x1)
29+
test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int) => x1)
30+
test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int) => x1)
31+
test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int) => x1)
32+
test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int) => x1)
33+
test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int) => x1)
34+
test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int) => x1)
35+
test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int) => x1)
36+
test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int) => x1)
37+
test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int) => x1)
38+
test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int) => x1)
39+
test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int) => x1)
40+
test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int, x21: Int) => x1)
41+
test((x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int, x21: Int, x22: Int) => x1)
42+
43+
test({
44+
case x: Int => x
45+
}: PartialFunction[Int, Int], sp = true)
46+
47+
test({
48+
case x: Int => x
49+
}: PartialFunction[Any, Any])
50+
51+
test({
52+
case x: Int => ()
53+
}: PartialFunction[Int, Unit], sp = true)
54+
55+
test({
56+
case x: String => 1
57+
}: PartialFunction[String, Int])
58+
59+
test({
60+
case x: String => ()
61+
}: PartialFunction[String, Unit])
62+
63+
test({
64+
case x: String => x
65+
}: PartialFunction[String, String])
66+
}

0 commit comments

Comments
 (0)