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

Loosen the self-type constraint for Net::HTTPHeader #1932

Merged
merged 1 commit into from
Jul 19, 2024

Conversation

hibariya
Copy link
Contributor

Net::HTTPHeader could be included by classes that do not inherit ::Object and we need to loosen the self-type constraint.

For example, HTTParty::Response::Headers, which includes Net::HTTPHeader, inherits SimpleDelegator < Delegator < BasicObject. With the current definition, it causes an error like below:

/workspaces/gem_rbs_collection/gems/httparty/0.18/_test/.gem_rbs_collection/httparty/0.18/httparty.rbs:453:6: [error] Module self type constraint in type `::HTTParty::Response::Headers` doesn't satisfy: `::HTTParty::Response::Headers <: ::Object`
│ Diagnostic ID: RBS::ModuleSelfTypeError
│
└       include Net::HTTPHeader
        ~~~~~~~~~~~~~~~~~~~~~~~

Note that to reproduce the error above, you need to modify the manifest.yml like below:

diff --git a/gems/httparty/0.18/manifest.yaml b/gems/httparty/0.18/manifest.yaml
index a5128c3..8d0d7ab 100644
--- a/gems/httparty/0.18/manifest.yaml
+++ b/gems/httparty/0.18/manifest.yaml
@@ -1,3 +1,4 @@
 dependencies:
   - name: uri
   - name: net-http
+  - name: delegate

I also considered defining an interface instead of using BasicObject at first, but it seems the following syntax is illegal.

interface _HasHeader
  @header: Hash[String,  untyped]
end

@ParadoxV5
Copy link
Contributor

Should top be the default self constraint for all modules?

@soutaro soutaro added this to the RBS 3.6 milestone Jul 19, 2024
Copy link
Member

@soutaro soutaro left a comment

Choose a reason for hiding this comment

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

👍

@soutaro
Copy link
Member

soutaro commented Jul 19, 2024

I don't think changing the default of self-constraint to top makes sense.
Instead, we may want to consider allowing instance variables in interfaces. (But what does interface mean then?)

@soutaro soutaro added this pull request to the merge queue Jul 19, 2024
Merged via the queue into ruby:master with commit 9648cbd Jul 19, 2024
19 checks passed
@ParadoxV5
Copy link
Contributor

But what does interface mean then?

a shape? which might detail instance vars and constants as well as methods?

@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.

3 participants