8000 Modules w. serializable type alias "companions" are not serializable · retronym/scala@64a0ec4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 64a0ec4

Browse files
committed
Modules w. serializable type alias "companions" are not serializable
The behaviour changed in scala#5550, this commit adapts to the change so that we'll be binary compatible after boostrapping. MiMa alerted us to a change in the parentage of two objects in the forkjoin package object. In Scala 2.12.0/1, they implemented `scala.Serializable`. Recently, this (synthetically added) parent was absent. This appears to be due to a bug fix in `companionSymbolOf`, which no longer treats objects and same-named type aliases to be companions. This commit manually adds the formerly-synthetic parents to these objects, and documents the change in compiler behaviour with a test. Fixes scala/scala-dev#290
1 parent 4c0a9f1 commit 64a0ec4

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

src/library/scala/concurrent/forkjoin/package.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ package object forkjoin {
2525
@deprecated("use java.util.concurrent.ForkJoinTask directly, instead of this alias", "2.12.0")
2626
type ForkJoinTask[T] = juc.ForkJoinTask[T]
2727
@deprecated("use java.util.concurrent.ForkJoinTask directly, instead of this alias", "2.12.0")
28-
object ForkJoinTask {
28+
object ForkJoinTask extends scala.Serializable {
2929
def adapt(runnable: Runnable): ForkJoinTask[_] = juc.ForkJoinTask.adapt(runnable)
3030
def adapt[T](callable: juc.Callable[_ <: T]): ForkJoinTask[T] = juc.ForkJoinTask.adapt(callable)
3131
def adapt[T](runnable: Runnable, result: T): ForkJoinTask[T] = juc.ForkJoinTask.adapt(runnable, result)
@@ -51,7 +51,7 @@ package object forkjoin {
5151
@deprecated("use java.util.concurrent.ThreadLocalRandom directly, instead of this alias", "2.12.0")
5252
type ThreadLocalRandom = juc.ThreadLocalRandom
5353
@deprecated("use java.util.concurrent.ThreadLocalRandom directly, instead of this alias", "2.12.0")
54-
object ThreadLocalRandom {
54+
object ThreadLocalRandom extends scala.Serializable {
5555
// For source compatibility, current must declare the empty argument list.
5656
// Having no argument list makes more sense since it doesn't have any side effects,
5757
// but existing callers will break if they invoked it as `current()`.

test/files/run/SD-290.scala

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
object p1 {
2+
class B
3+
object B
4+
5+
class C extends java.io.Serializable
6+
object C
7+
8+
type D = DD
9+
object D
10+
}
11+
package object p2 {
12+
class B
13+
object B
14+
15+
class C extends java.io.Serializable
16+
object C
17+
18+
type D = DD
19+
object D
20+
21+
}
22+
class DD extends java.io.Serializable
23+
24+
object Test {
25+
def main(args: Array[String]): Unit = {
26+
27+
// This is the behaviour that was intended and was unchanged by this commmit.
28+
assert(!(p1.B : Object).isInstanceOf[scala.Serializable])
29+
assert(p1.C.isInstanceOf[scala.Serializable])
30+
assert(!(p1.D: Object).isInstanceOf[scala.Serializable])
31+
32+
assert(!(p2.B : Object).isInstanceOf[scala.Serializable])
33+
assert(p2.C.isInstanceOf[scala.Serializable])
34+
35+
// this behaviour was different in 2.12.1 and earlier due to a bug
36+
// in companionSymbolOf
37+
assert(!(p2.D: Object).isInstanceOf[scala.Serializable])
38+
}
39+
}

0 commit comments

Comments
 (0)
0