class RuboCop::AST::NodePattern::Compiler
def unify_in_union(enum)
def unify_in_union(enum) # We need to reset @unify before each branch is processed. # Moreover we need to keep track of newly encountered wildcards. # Var `new_unify_intersection` will hold those that are encountered # in all branches; these are not a problem. # Var `partial_unify` will hold those encountered in only a subset # of the branches; these can't be used outside of the union. return to_enum __method__, enum unless block_given? new_unify_intersection = nil partial_unify = [] unify_before = @unify.dup result = enum.each do |e| @unify = unify_before.dup if new_unify_intersection yield e new_unify = @unify.keys - unify_before.keys if new_unify_intersection.nil? # First iteration new_unify_intersection = new_unify else union = new_unify_intersection | new_unify new_unify_intersection &= new_unify partial_unify |= union - new_unify_intersection end end # At this point, all members of `new_unify_intersection` can be used # for unification outside of the union, but partial_unify may not forbid_unification(*partial_unify) result end