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

Object#define_singleton_method does not accept a Proc as second arguments #803

Closed
satoryu opened this issue Sep 21, 2021 · 4 comments · Fixed by #1431
Closed

Object#define_singleton_method does not accept a Proc as second arguments #803

satoryu opened this issue Sep 21, 2021 · 4 comments · Fixed by #1431
Labels
rbs Issues of RBS type definition
Milestone

Comments

@satoryu
Copy link
Contributor

satoryu commented Sep 21, 2021

Here is example

# foo.rb
class Foo
  def foo(&block)
    define_singleton_method(:bar, block)
  end
end

Foo.new.foo { |i| (i * i) }
class Foo
  def foo: { (Integer) -> untyped } -> untyped
end

steep check shows the following message:

# Type checking files:

............................................................F

lib/foo.rb:3:4: [error] Cannot find compatible overloading of method `define_singleton_method` of type `::Foo`
│ Method types:
│   def define_singleton_method: (::Symbol, (::Method | ::UnboundMethod)) -> ::Symbol
│                              | (::Symbol) { (*untyped) -> untyped } -> ::Symbol
│
│ Diagnostic ID: Ruby::UnresolvedOverloading
│
└     define_singleton_method(:bar, block)
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I tried to fix it but could not. please see #802

@pocke
Copy link
Member

pocke commented Sep 30, 2021

Thanks for your reporting 👍

Could you describe how #802 didn't work well?

@satoryu
Copy link
Contributor Author

satoryu commented Oct 3, 2021

I expected that define_singleton_method(:bar, block) in Foo#foo matches with define_singleton_method: (::Symbol, ^(*untyped) -> untyped) -> Symbol but not and still `steep check says the same error:

$ steep check
# Type checking files:

........................................F....................

lib/foo.rb:3:4: [error] Cannot find compatible overloading of method `define_singleton_method` of type `::Foo`
│ Method types:
│   def define_singleton_method: (::Symbol, (::Method | ::UnboundMethod | ^(*untyped) -> untyped)) -> ::Symbol
│                              | (::Symbol) { (*untyped) -> untyped } -> ::Symbol
│
│ Diagnostic ID: Ruby::UnresolvedOverloading
│
└     define_singleton_method(:bar, block)
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Detected 1 problem from 1 file

@satoryu
Copy link
Contributor Author

satoryu commented Nov 11, 2021

image

Steep VS Code extension shows &block of the method foo is untyped not Proc I expected.

I confirmed this error is resolved by adding the following overload to the rbs:

class ::Object
  def define_singleton_method: (::Symbol, untyped) -> ::Symbol |
                               ...
end

@soutaro soutaro added this to the RBS 3.2 milestone Apr 26, 2023
@soutaro soutaro added the rbs Issues of RBS type definition label Apr 26, 2023
@ParadoxV5
Copy link
Contributor

Hey folks, reminder to check if the &block issue is resolved. #802 may be reöpened if it’s no longer a hinderance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rbs Issues of RBS type definition
Development

Successfully merging a pull request may close this issue.

4 participants