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

Improve interface check by method parameters #1698

Merged
merged 4 commits into from
Jan 9, 2024

Conversation

ksss
Copy link
Collaborator

@ksss ksss commented Dec 25, 2023

Regarding checking interfaces, in addition to checking with #respond_to?, I believe that comparing Method#parameters with types can provide a more accurate interface check.

As an implementation, I've made it so that a match only occurs if the method has exactly the same arguments as the type notation.
Does this match with the philosophy of RBS?
For example, the following code actually works.

# sample.rbs
class Sample
  def foo: (a: Integer, b: String) -> void
end
# sample.rb
class Sample
  def foo(a = {})
    p a # { :a => 1, :b => 'b' }
  end
end

Sample.new.foo(a: 1, b: 'b')

However, for instance, steep would report Ruby::MethodArityMismatch and Ruby::DifferentMethodParameterKind.
What kind of checks should be attempted with RBS alone?

@soutaro soutaro added this to the RBS 3.5 milestone Dec 26, 2023
@soutaro
Copy link
Member

soutaro commented Dec 26, 2023

I think the parameter checking should be permissive. Having an optional argument in implementation while required argument in RBS should be allowed for example.

@soutaro
Copy link
Member

soutaro commented Dec 26, 2023

Steep validates the method implementation and reports DifferentMethodParameterKind. But I don't think RBS should do it on the implementation side.

@ksss
Copy link
Collaborator Author

ksss commented Dec 26, 2023

Thank you!
I think it seems good to use the criterion "if it can be called, it's OK"

@ksss
Copy link
Collaborator Author

ksss commented Jan 5, 2024

I have reimplemented code to allow for many method call patterns.
I also added an ArgumentChecker to generate arguments from RBS and test whether a method can actually be called.

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.

Didn't review the implementation very carefully, but give it a try! 💪

@soutaro soutaro added this pull request to the merge queue Jan 9, 2024
Merged via the queue into ruby:master with commit 5142125 Jan 9, 2024
15 checks passed
@ksss ksss deleted the rbs-test-interface branch January 9, 2024 05:33
@soutaro soutaro added the Released PRs already included in the released version label Jun 6, 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.

2 participants