generalize fix for __flatten_pattern_tree__