Skip to content

Commit dbbb012

Browse files
author
Michel Davit
authored
[shared] Add scala 2.12 CanBuildFrom for Set (#942)
* [shared] Add scala 2.12 CanBuildFrom for Set Set could be use as collection in scala 2.13 but not in 2.12 due to a missing serializable can build from factory. * FIx protobuf tests * FIx custom equal/hashcode on test Collections
1 parent ee3371c commit dbbb012

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

protobuf/src/test/protobuf/Proto2.proto

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ message CollectionP2 {
4545
repeated int32 a = 1;
4646
repeated int32 l = 2;
4747
repeated int32 v = 3;
48+
repeated int32 s = 4;
4849
}
4950

5051
message MoreCollectionP2 {

protobuf/src/test/protobuf/Proto3.proto

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ message CollectionP3 {
4545
repeated int32 a = 1;
4646
repeated int32 l = 2;
4747
repeated int32 v = 3;
48+
repeated int32 s = 4;
4849
}
4950

5051
message MoreCollectionP3 {

shared/src/main/scala-2.12/magnolify/shims/SerializableCanBuildFrom.scala

+6-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ trait SerializableCanBuildFromLowPrio3 extends SerializableCanBuildFromLowPrio4
5656
SerializableCanBuildFrom(Stream.newBuilder[A])
5757
}
5858

59-
trait SerializableCanBuildFromLowPrio4 {
59+
trait SerializableCanBuildFromLowPrio4 extends SerializableCanBuildFromLowPrio5 {
6060
implicit def lazyListCBF[A]: SerializableCanBuildFrom[Any, A, LazyList[A]] =
6161
SerializableCanBuildFrom(LazyList.newBuilder[A])
6262
}
63+
64+
trait SerializableCanBuildFromLowPrio5 {
65+
implicit def setCBF[A]: SerializableCanBuildFrom[Any, A, Set[A]] =
66+
SerializableCanBuildFrom(Set.newBuilder[A])
67+
}

test/src/test/scala/magnolify/test/Simple.scala

+4-2
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,23 @@ object Simple {
5151
o: Option[Required],
5252
l: List[Required]
5353
)
54-
case class Collections(a: Array[Int], l: List[Int], v: Vector[Int]) {
54+
case class Collections(a: Array[Int], l: List[Int], v: Vector[Int], s: Set[Int]) {
5555

5656
override def hashCode(): Int = {
5757
var hash = 1
5858
hash = 31 * hash + util.Arrays.hashCode(a)
5959
hash = 31 * hash + Objects.hashCode(l)
6060
hash = 31 * hash + Objects.hashCode(v)
61+
hash = 31 * hash + Objects.hashCode(s)
6162
hash
6263
}
6364

6465
override def equals(obj: Any): Boolean = obj match {
6566
case that: Collections =>
6667
Objects.deepEquals(this.a, that.a) &&
6768
Objects.equals(this.l, that.l) &&
68-
Objects.equals(this.v, that.v)
69+
Objects.equals(this.v, that.v) &&
70+
Objects.equals(this.s, that.s)
6971
case _ => false
7072
}
7173
}

0 commit comments

Comments
 (0)