Skip to content
This repository was archived by the owner on Jan 24, 2025. It is now read-only.

Commit c9eb678

Browse files
committed
Fix propagating child modifications throughout the DiffContext
This relates to #418
1 parent ea0201d commit c9eb678

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

core/src/main/scala/com/softwaremill/diffx/DiffContext.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ object Tree {
6767
def empty[T]: Node[T] = Tree.Node[T](Map.empty)
6868

6969
case class Leaf[T](v: T) extends Tree[T] {
70-
override def merge(tree: Tree[T]): Tree[T] = this
70+
override def merge(tree: Tree[T]): Tree[T] = tree
7171
}
7272
case class Node[T](tries: Map[ModifyPath, Tree[T]]) extends Tree[T] {
7373
override def merge(tree: Tree[T]): Tree[T] = {

core/src/test/scala/com/softwaremill/diffx/test/DiffModifyIntegrationTest.scala

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,4 +320,31 @@ class DiffModifyIntegrationTest extends AnyFlatSpec with Matchers with AutoDeriv
320320
)
321321
)
322322
}
323+
324+
it should "allow propagate modification from substituted diff instance" in {
325+
case class Address(house: Int, street: String)
326+
case class Person(name: String, address: Address)
327+
328+
val add = Diff.summon[Address].ignore(_.house)
329+
val d = Diff
330+
.summon[Person]
331+
.modify(_.address)
332+
.setTo(add)
333+
334+
val a1 = Address(123, "Robin St.")
335+
val a2 = Address(456, "Robin St.")
336+
337+
val p1 = Person("Mason", a1)
338+
val p2 = Person("Mason", a2)
339+
d(p1, p2) shouldBe DiffResultObject(
340+
"Person",
341+
ListMap(
342+
"name" -> IdenticalValue("Mason"),
343+
"address" -> DiffResultObject(
344+
"Address",
345+
ListMap("house" -> IdenticalValue("<ignored>"), "street" -> IdenticalValue("Robin St."))
346+
)
347+
)
348+
)
349+
}
323350
}

0 commit comments

Comments
 (0)