rbs icon indicating copy to clipboard operation
rbs copied to clipboard

Inconsistencies around Method / block / Proc

Open HoneyryderChuck opened this issue 4 years ago • 2 comments

I'm getting a few issues in steep which might be directly related to rbs. Take the following example into account:

# rbs
class A
   EX: ^(String name) -> bool

  def each:  () { (String) -> void } -> void
                 | () -> Enumerable[String]

end

class B
  def initialize: (^(String) -> void) -> untyped
end

I get the following errors for the following code:

# given an instance of A
def bla(str)
  puts str
end
a.each(&method(:bla))

# steep error: Cannot pass a value of type `::Method` as a block-pass-argument of type `^(...

class A

  CHECK_IF_IP = Proc.new { |x| }
  # steep error: Cannot assign a value of type `::Proc` to a constant of type `^(::String) -> bool`
  #  ::Proc <: ^(::String) -> bool(Ruby::IncompatibleAssignment)
  #
  # this goes away when I redefine with ->(x) ...

  def each(&block)

    B.new(block)
    # steep error: Cannot pass a value of type `(^(::String) -> void | nil)` as an argument of type `^(::String) -> void`
    #  (^(::String) -> void | nil) <: ^(::String) -> void
    #    nil <: ^(::String) -> void(Ruby::ArgumentTypeMismatch)

    block["bla"]
    # steep error: Type `(^(::String) -> void | nil)` does not have method `[]`(Ruby::NoMethod)

HoneyryderChuck avatar Aug 09 '21 13:08 HoneyryderChuck

I know it's a problem (of Steep). Steep doesn't understand the relationship between Method, Proc, and lambda types.

soutaro avatar Aug 13 '21 08:08 soutaro

Steep doesn't understand the relationship between Method, Proc, and lambda types.

Put "objects implementing #call with same sig/return" in the same bucket :) . I think that addressing "callable" objects is what's missing ATM.

HoneyryderChuck avatar Aug 17 '21 10:08 HoneyryderChuck