-
Notifications
You must be signed in to change notification settings - Fork 161
Filter out mixins that weren't performed in current gem #1012
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -168,6 +168,17 @@ def required_from_location | |
|
|
||
| required_location.absolute_path || "" | ||
| end | ||
|
|
||
| sig { params(constant: Module).returns(T.nilable(String)) } | ||
| def constant_name_from_singleton_class(constant) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I moved these two methods into reflection because I had to use them in |
||
| constant.to_s.match("#<Class:(.+)>")&.captures&.first | ||
| end | ||
|
|
||
| sig { params(constant: Module).returns(T.nilable(BasicObject)) } | ||
| def constant_from_singleton_class(constant) | ||
| constant_name = constant_name_from_singleton_class(constant) | ||
| constantize(constant_name) if constant_name | ||
| end | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,26 +28,18 @@ class Type < T::Enum | |
| def self.register(constant, mixin, mixin_type) | ||
| location = Reflection.required_from_location | ||
|
|
||
| locs = mixin_locations_for(constant) | ||
| locs.fetch(mixin_type).store(mixin, location) | ||
|
|
||
| constants = constants_with_mixin(mixin) | ||
| constants[constant] = location | ||
| constants.fetch(mixin_type).store(constant, location) | ||
| end | ||
|
|
||
| sig { params(constant: Module).returns(T::Hash[Type, T::Hash[Module, String]]) } | ||
| def self.mixin_locations_for(constant) | ||
| @constants_to_mixin_locations[constant] ||= { | ||
| sig { params(mixin: Module).returns(T::Hash[Type, T::Hash[Module, String]]) } | ||
| def self.constants_with_mixin(mixin) | ||
| @mixins_to_constants[mixin] ||= { | ||
| Type::Prepend => {}.compare_by_identity, | ||
| Type::Include => {}.compare_by_identity, | ||
| Type::Extend => {}.compare_by_identity, | ||
| } | ||
| end | ||
|
|
||
| sig { params(mixin: Module).returns(T::Hash[Module, String]) } | ||
| def self.constants_with_mixin(mixin) | ||
| @mixins_to_constants[mixin] ||= {}.compare_by_identity | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
@@ -61,6 +53,9 @@ def prepend_features(constant) | |
| self, | ||
| Tapioca::Runtime::Trackers::Mixin::Type::Prepend, | ||
| ) | ||
|
|
||
| register_extend_on_attached_class(constant) if constant.singleton_class? | ||
|
|
||
| super | ||
| end | ||
|
|
||
|
|
@@ -70,6 +65,9 @@ def append_features(constant) | |
| self, | ||
| Tapioca::Runtime::Trackers::Mixin::Type::Include, | ||
| ) | ||
|
|
||
| register_extend_on_attached_class(constant) if constant.singleton_class? | ||
|
|
||
| super | ||
| end | ||
|
|
||
|
|
@@ -81,5 +79,21 @@ def extend_object(obj) | |
| ) if Module === obj | ||
| super | ||
| end | ||
|
|
||
| private | ||
|
|
||
| # Including or prepending on a singleton class is functionally equivalent to extending the | ||
| # attached class. Registering the mixin as an extend on the attached class ensures that | ||
| # this mixin can be found whether searching for an include/prepend on the singleton class | ||
| # or an extend on the attached class. | ||
| def register_extend_on_attached_class(constant) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This functionality was moved from |
||
| attached_class = Tapioca::Runtime::Reflection.constant_from_singleton_class(constant) | ||
|
|
||
| Tapioca::Runtime::Trackers::Mixin.register( | ||
| T.cast(attached_class, Module), | ||
| self, | ||
| Tapioca::Runtime::Trackers::Mixin::Type::Extend, | ||
| ) if attached_class | ||
| end | ||
| end) | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1096,10 +1096,9 @@ module TypedParameters | |
| assert_includes(response.out, "Compiled actionpack") | ||
| assert_includes(response.out, "Compiled typed_parameters") | ||
|
|
||
| # TODO: Uncomment when addressing part 2 of tapioca#890 | ||
| # actionpack_rbi = @project.read("sorbet/rbi/gems/[email protected]") | ||
| actionpack_rbi = @project.read("sorbet/rbi/gems/[email protected]") | ||
| # actionpack RBI should have nothing in it about `TypedParameters` | ||
| # refute_includes(actionpack_rbi, "TypedParameters") | ||
| refute_includes(actionpack_rbi, "TypedParameters") | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This assertion passes now 馃帀 |
||
|
|
||
| assert_project_file_equal("sorbet/rbi/gems/[email protected]", <<~RBI) | ||
| # typed: true | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -313,16 +313,11 @@ def hello; end | |
|
|
||
| object_output = template(<<~RBI) | ||
| class Object < ::BasicObject | ||
| include ::Kernel | ||
|
egiurleo marked this conversation as resolved.
|
||
|
|
||
| def hello; end | ||
| end | ||
| RBI | ||
|
|
||
| compiled = compile | ||
| .gsub(/^\s+include ::Minitest::Expectations\s/, "") | ||
| .gsub(/^\s+include ::JSON::Ext::Generator::GeneratorMethods::Object\s/, "") | ||
| .gsub(/^\s+include ::PP::ObjectMixin\s/, "") | ||
|
Comment on lines
-323
to
-325
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @paracycle Is this gsub you were talking about? |
||
|
|
||
| assert_includes(compiled, basic_object_output) | ||
| assert_includes(compiled, object_output) | ||
|
|
@@ -446,8 +441,6 @@ def bar; end | |
| output = template(<<~RBI) | ||
| class Array | ||
| include ::Foo::Bar | ||
| include ::Enumerable | ||
| include ::JSON::Ext::Generator::GeneratorMethods::Array | ||
|
|
||
| def foo_int; end | ||
| end | ||
|
|
@@ -460,8 +453,6 @@ def to_s; end | |
| module Foo::Bar; end | ||
|
|
||
| class Hash | ||
| include ::Enumerable | ||
| include ::JSON::Ext::Generator::GeneratorMethods::Hash | ||
| extend ::Foo::Bar | ||
|
|
||
| def to_bar; end | ||
|
|
@@ -472,10 +463,7 @@ def bar; end | |
| end | ||
|
|
||
| class String | ||
| include ::Comparable | ||
| include ::JSON::Ext::Generator::GeneratorMethods::String | ||
| include ::Foo::Bar | ||
| extend ::JSON::Ext::Generator::GeneratorMethods::String::Extend | ||
|
|
||
| def to_foo(base = T.unsafe(nil)); end | ||
| end | ||
|
|
@@ -519,8 +507,6 @@ class Array | |
| output = template(<<~RBI) | ||
| class Array | ||
| include ::Foo::Bar | ||
| include ::Enumerable | ||
| include ::JSON::Ext::Generator::GeneratorMethods::Array | ||
| end | ||
|
|
||
| class Foo | ||
|
|
@@ -531,16 +517,11 @@ def to_s; end | |
| module Foo::Bar; end | ||
|
|
||
| class Hash | ||
| include ::Enumerable | ||
| include ::JSON::Ext::Generator::GeneratorMethods::Hash | ||
| extend ::Foo::Bar | ||
| end | ||
|
|
||
| class String | ||
| include ::Comparable | ||
| include ::JSON::Ext::Generator::GeneratorMethods::String | ||
| include ::Foo::Bar | ||
| extend ::JSON::Ext::Generator::GeneratorMethods::String::Extend | ||
| end | ||
| RBI | ||
|
|
||
|
|
@@ -571,8 +552,6 @@ module Bar; end | |
| output = template(<<~RBI) | ||
| class Array | ||
| include ::Foo::Bar | ||
| include ::Enumerable | ||
| include ::JSON::Ext::Generator::GeneratorMethods::Array | ||
| end | ||
|
|
||
| class Foo | ||
|
|
@@ -583,16 +562,11 @@ def to_s; end | |
| module Foo::Bar; end | ||
|
|
||
| class Hash | ||
| include ::Enumerable | ||
| include ::JSON::Ext::Generator::GeneratorMethods::Hash | ||
| extend ::Foo::Bar | ||
| end | ||
|
|
||
| class String | ||
| include ::Comparable | ||
| include ::JSON::Ext::Generator::GeneratorMethods::String | ||
| include ::Foo::Bar | ||
| extend ::JSON::Ext::Generator::GeneratorMethods::String::Extend | ||
| end | ||
| RBI | ||
|
|
||
|
|
@@ -2431,9 +2405,6 @@ def self.name | |
| output = template(<<~RBI) | ||
| class Foo | ||
| extend ::T::Props | ||
| extend ::T::Props::Plugin | ||
| extend ::T::Props::Optional | ||
| extend ::T::Props::WeakConstructor | ||
| extend ::T::Props::Constructor | ||
|
|
||
| class << self | ||
|
|
@@ -2851,10 +2822,6 @@ def do_it; end | |
| end | ||
|
|
||
| class Buzz | ||
| include ::T::Props | ||
| include ::T::Props::Plugin | ||
| include ::T::Props::Optional | ||
| include ::T::Props::WeakConstructor | ||
| include ::T::Props::Constructor | ||
| extend ::T::Props::ClassMethods | ||
| extend ::T::Props::Plugin::ClassMethods | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method was moved into
Runtime::Reflection