Skip to content

Commit

Permalink
Merge pull request #967 from Shopify/interesting-ancestors-refactor
Browse files Browse the repository at this point in the history
Refactor the interesting_ancestors_of method in the Mixins tracker
  • Loading branch information
egiurleo authored Jun 6, 2022
2 parents ce75791 + 8414af4 commit b0990a9
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lib/tapioca/gem/listeners/mixins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,8 @@ def filtered_mixin?(mixin_name)

sig { params(constant: Module).returns(T::Array[Module]) }
def interesting_ancestors_of(constant)
inherited_ancestors_ids = Set.new(
inherited_ancestors_of(constant).map { |mod| object_id_of(mod) }
)
inherited_ancestors = Set.new.compare_by_identity.merge(inherited_ancestors_of(constant))

# TODO: There is actually a bug here where this will drop modules that
# may be included twice. For example:
#
Expand All @@ -91,9 +90,9 @@ def interesting_ancestors_of(constant)
#
# Instead, we should only drop the tail matches of the ancestors and
# inherited ancestors, past the location of the constant itself.
constant.ancestors.reject do |mod|
inherited_ancestors_ids.include?(object_id_of(mod))
end
ancestors = Set.new.compare_by_identity.merge(ancestors_of(constant))

(ancestors - inherited_ancestors).to_a
end
end
end
Expand Down

0 comments on commit b0990a9

Please sign in to comment.