diff --git a/Modules/RDTs/src/main/scala/rdts/datatypes/LastWriterWins.scala b/Modules/RDTs/src/main/scala/rdts/datatypes/LastWriterWins.scala index 1db681de3..99c3f6ea9 100644 --- a/Modules/RDTs/src/main/scala/rdts/datatypes/LastWriterWins.scala +++ b/Modules/RDTs/src/main/scala/rdts/datatypes/LastWriterWins.scala @@ -28,7 +28,7 @@ case class LastWriterWins[+A](timestamp: CausalTime, payload: A) { object LastWriterWins { - def empty[A: Bottom]: LastWriterWins[A] = now(Bottom.empty) + def empty[A: Bottom]: LastWriterWins[A] = LastWriterWins(Bottom[CausalTime].empty, Bottom[A].empty) def fallback[A](v: A): LastWriterWins[A] = LastWriterWins(rdts.time.CausalTime(Long.MinValue, 0, CausalTime.countedTime()), v) diff --git a/Modules/RDTs/src/test/scala/test/rdts/bespoke/LastWriterWinsTest.scala b/Modules/RDTs/src/test/scala/test/rdts/bespoke/LastWriterWinsTest.scala index a4ae287d9..b3d58a366 100644 --- a/Modules/RDTs/src/test/scala/test/rdts/bespoke/LastWriterWinsTest.scala +++ b/Modules/RDTs/src/test/scala/test/rdts/bespoke/LastWriterWinsTest.scala @@ -35,4 +35,17 @@ class LastWriterWinsTest extends munit.FunSuite { assertEquals(merged.read, "Hello Distributed World") } + test("newer Bottom does not overwrite an earlier initial value") { + import LastWriterWins.given + + val lww1 = LastWriterWins.now("Hello Distributed World") + val lww2 = Bottom[LastWriterWins[String]].empty + + assertNotEquals(lww1.timestamp, lww2.timestamp) + + val merged = lww1 merge lww2 + + assertEquals(merged.read, "Hello Distributed World") + } + }