Skip to content

Commit

Permalink
Refactor the interesting_ancestors_of method in the Mixins tracker
Browse files Browse the repository at this point in the history
Co-authored-by: Ufuk Kayserilioglu <ufuk.kayserilioglu@shopify.com>
  • Loading branch information
egiurleo and paracycle committed Jun 6, 2022
1 parent ce75791 commit 8414af4
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 8414af4

Please sign in to comment.