@@ -246,8 +246,7 @@ function ArrayNode{T,D}(
246246 child_idx
247247 else
248248 # Different tree - copy
249- new_idx = copy_subtree! (tree, child_tree, child_idx)
250- new_idx
249+ copy_subtree! (tree, child_tree, child_idx)
251250 end
252251 else
253252 UInt16 (0 )
@@ -340,19 +339,44 @@ end
340339function set_children! (n:: ArrayNode{T,D,S} , cs:: Tuple ) where {T,D,S}
341340 tree = getfield (n, :tree )
342341 idx = getfield (n, :idx )
343- child_indices = ntuple (i -> begin
342+ child_indices = ntuple (Val (D)) do i
344343 if i <= length (cs)
345344 child = cs[i]
346- if isa (child, ArrayNode)
347- getfield (child, :idx )
345+ if isa (child, Nullable)
346+ # Handle Nullable wrapped children
347+ if child. null
348+ UInt16 (0 )
349+ else
350+ child_node = child. x
351+ child_tree = getfield (child_node, :tree )
352+ child_idx = getfield (child_node, :idx )
353+ if child_tree === tree
354+ # Same tree - just use the index
355+ child_idx
356+ else
357+ # Different tree - need to copy the subtree
358+ copy_subtree! (tree, child_tree, child_idx)
359+ end
360+ end
361+ elseif isa (child, ArrayNode)
362+ child_tree = getfield (child, :tree )
363+ child_idx = getfield (child, :idx )
364+ if child_tree === tree
365+ # Same tree - just use the index
366+ child_idx
367+ else
368+ # Different tree - need to copy the subtree
369+ copy_subtree! (tree, child_tree, child_idx)
370+ end
348371 else
349372 UInt16 (0 )
350373 end
351374 else
352375 UInt16 (0 )
353376 end
354- end , Val (D))
355- return tree. nodes. children[idx] = child_indices
377+ end
378+ tree. nodes. children[idx] = child_indices
379+ return nothing
356380end
357381
358382# Copy
0 commit comments