Fixes a stack-overflow exception in expander's flatten.