rbs icon indicating copy to clipboard operation
rbs copied to clipboard

Object#define_singleton_method does not accept a Proc as second arguments

Open satoryu opened this issue 4 years ago • 3 comments

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

satoryu avatar Sep 21 '21 09:09 satoryu

Thanks for your reporting :+1:

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

pocke avatar Sep 30 '21 09:09 pocke

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 avatar Oct 03 '21 04:10 satoryu

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

satoryu avatar Nov 11 '21 03:11 satoryu

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

ParadoxV5 avatar Jul 27 '23 22:07 ParadoxV5