From 3d98a13b0157e0916ee17531ab696352864b5e93 Mon Sep 17 00:00:00 2001 From: Igor Malovitsa Date: Thu, 17 Sep 2026 06:53:56 +0000 Subject: [PATCH] Fix list node join of two empty children under one key --- src/line_list_node.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/line_list_node.rs b/src/line_list_node.rs index 85c8f24e..6dd77fbe 100644 --- a/src/line_list_node.rs +++ b/src/line_list_node.rs @@ -1325,7 +1325,11 @@ fn merge_guts<'a, V: Clone + Lattice + Send + Sync, A: Allocator, const ASLOT: u (true, true) => { //both are child nodes, so join them let a_child = unsafe{ a.child_in_slot::() }; let b_child = unsafe{ b.child_in_slot::() }; - return a_child.pjoin(b_child).map(|new_child| (a_key, ValOrChild::Child(new_child))) + return match a_child.pjoin(b_child) { + //Two empty children are both just the dangling path + AlgebraicResult::None => AlgebraicResult::Identity(SELF_IDENT | COUNTER_IDENT), + joined => joined.map(|new_child| (a_key, ValOrChild::Child(new_child))), + } }, (false, false) => { //both are values, so join them let a_val = unsafe{ a.val_in_slot::() }; @@ -3984,4 +3988,20 @@ mod tests { m.write_zipper().restrict(&o.read_zipper()); assert_eq!(keys(&m), ["bx"]); } + + /// Joining two nodes whose children under the same key are both empty + #[test] + fn merge_empty_children_under_same_key() { + let node = || { + let mut n = LineListNode::::new_in(global_alloc()); + let child = LineListNode::::new_in(global_alloc()); + unsafe { n.set_child_0(&[0, 3], TrieNodeODRc::new_in(child, global_alloc())); } + n + }; + let (a, b) = (node(), node()); + match merge_list_nodes(&a, &b) { + Ok(AlgebraicResult::Identity(mask)) => assert_eq!(mask, SELF_IDENT | COUNTER_IDENT), + _ => panic!("expected an identity"), + } + } }