Skip to content

Commit

Permalink
TreeMap is serialization compat with 2.12.10 again
Browse files Browse the repository at this point in the history
Explicitly lock down the SerialVersionUID and avoid having
scalac mangle the name of the `tree` field to make it non-private.

Reinstate serialization compatibility tests for this and other
collections that were temporarily disabled due to an interation
with -Xcheckinit. Now, we simply skip the test when we detect
that the build is using that option.
  • Loading branch information
retronym committed Mar 2, 2020
1 parent f139b61 commit 98a5944
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 32 deletions.
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ val mimaFilterSettings = Seq {
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.immutable.Map#Map4.foreachEntry"),
ProblemFilters.exclude[MissingTypesProblem]("scala.collection.immutable.ListMap"),
ProblemFilters.exclude[MissingTypesProblem]("scala.collection.immutable.TreeMap"),
ProblemFilters.exclude[MissingFieldProblem]("scala.collection.immutable.TreeMap.serialVersionUID"),
ProblemFilters.exclude[MissingTypesProblem]("scala.collection.immutable.HashMap"),
ProblemFilters.exclude[MissingTypesProblem]("scala.collection.immutable.HashMap$HashMap1"),
ProblemFilters.exclude[MissingTypesProblem]("scala.collection.immutable.HashMap$HashTrieMap"),
Expand Down
8 changes: 6 additions & 2 deletions src/library/scala/collection/immutable/TreeMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,16 @@ object TreeMap extends ImmutableSortedMapFactory[TreeMap] {
* @define mayNotTerminateInf
* @define willNotTerminateInf
*/
@SerialVersionUID(4714724050750123970L)
final class TreeMap[A, +B] private (tree: RB.Tree[A, B])(implicit val ordering: Ordering[A])
extends SortedMap[A, B]
with SortedMapLike[A, B, TreeMap[A, B]]
with MapLike[A, B, TreeMap[A, B]]
with Serializable
with HasForeachEntry[A, B] {
// Manually use this from inner classes to avoid having scalac rename `tree` to an expanded name which is not
// serialization compatbile.
private def tree0: RB.Tree[A, B] = tree

override protected[this] def newBuilder : Builder[(A, B), TreeMap[A, B]] =
TreeMap.newBuilder[A, B]
Expand Down Expand Up @@ -224,10 +228,10 @@ final class TreeMap[A, +B] private (tree: RB.Tree[A, B])(implicit val ordering:
}

override def keySet: SortedSet[A] = new DefaultKeySortedSet {
override def foreach[U](f: A => U): Unit = RB.foreachEntry(tree, {(key: A, _: B) => f(key)})
override def foreach[U](f: A => U): Unit = RB.foreachEntry(tree0, {(key: A, _: B) => f(key)})
}

override def values: scala.Iterable[B] = new DefaultValuesIterable {
override def foreach[U](f: B => U): Unit = RB.foreachEntry(tree, {(_: A, value: B) => f(value)})
override def foreach[U](f: B => U): Unit = RB.foreachEntry(tree0, {(_: A, value: B) => f(value)})
}
}
Loading

0 comments on commit 98a5944

Please sign in to comment.