Object#define_singleton_method does not accept a Proc as second arguments
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
Thanks for your reporting :+1:
Could you describe how #802 didn't work well?
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

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
Hey folks, reminder to check if the &block issue is resolved. #802 may be reöpened if it’s no longer a hinderance.