X-Git-Url: http://nitlanguage.org diff --git a/lib/ordered_tree.nit b/lib/ordered_tree.nit index 32cea45..d1dde15 100644 --- a/lib/ordered_tree.nit +++ b/lib/ordered_tree.nit @@ -128,7 +128,15 @@ class OrderedTree[E: Object] do var old_parent = parents.get_or_null(e) if old_parent != null then - sub[old_parent].remove(e) + var subs = sub[old_parent] + subs.remove(e) + if subs.is_empty then + # remove the sub when all children are detached + # so that `==` and `hash` are sane + # Otherwise an empty array will be considered + # differently than no array. + sub.keys.remove(old_parent) + end else if roots.has(e) then roots.remove(e) end