Skip to content
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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow alias to module-self-type from module #1948

Merged
merged 1 commit into from
Aug 2, 2024
Merged

Conversation

soutaro
Copy link
Member

@soutaro soutaro commented Aug 2, 2024

Defining an alias from a module to its module-self-type causes an error like

RBS::UnknownMethodAliasError: .../foo.rbs:2:2...2:18: Unknown method alias name: __id__ => foo (::Foo)

This PR fixes the problem.

@soutaro soutaro added this to the RBS 3.6 milestone Aug 2, 2024
@@ -2686,4 +2686,23 @@ module Bar : Foo
end
end
end

def test_alias__to_module_self_indierect_method
SignatureManager.new(system_builtin: false) do |manager|
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's really complicated to reproduce the problem.

Simply build_instance(TypeName("::Kernel")) doesn't fail, because the self_types are given through build_instance method.

Building ::Foo instance requires some of the methods of its module-self-type, ::Object. ::Object instance type requires the instance methods of ::Kernel, but it's done other than #build_instance method. So, the module-self-type methods are not injected, and causes the problem.

@@ -86,6 +86,19 @@ def define_instance(definition, type_name, subst)
one_ancestors = ancestor_builder.one_instance_ancestors(type_name)
methods = method_builder.build_instance(type_name)

self_type_methods = one_ancestors.each_self_type.with_object({}) do |self_type, hash| #$ Hash[Symbol, Definition::Method]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot simply inject the self_types methods to the result methods/definition, because the self_types methods may include other inherited methods, like #initialize and having them in the module is something unexpected.

@soutaro soutaro marked this pull request as ready for review August 2, 2024 13:45
@soutaro soutaro added this pull request to the merge queue Aug 2, 2024
@soutaro soutaro removed this pull request from the merge queue due to a manual request Aug 2, 2024
@soutaro soutaro force-pushed the alias-module-self-type branch from 84f7b37 to 3fe6743 Compare August 2, 2024 13:56
@soutaro soutaro enabled auto-merge August 2, 2024 13:56
@soutaro soutaro added this pull request to the merge queue Aug 2, 2024
Merged via the queue into master with commit c469a7d Aug 2, 2024
19 checks passed
@soutaro soutaro deleted the alias-module-self-type branch August 2, 2024 14:04
@soutaro soutaro added the Released PRs already included in the released version label Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Released PRs already included in the released version
Development

Successfully merging this pull request may close these issues.

1 participant