rbs icon indicating copy to clipboard operation
rbs copied to clipboard

override a function with a block fails

Open HoneyryderChuck opened this issue 2 years ago • 0 comments

  • rbs: 3.1.3
  • ruby: 3.2.2

i'm finding an issue typing the following structure:

class A
  def initialize(a, b)
    @a = a
    @b = b
  end
end

class B < A

  def initialize(a, b)
    super

    yield self if block_given?
end
class A
  def initialize: (Integer a, String b) -> void
end

class B
  def initialize: (Integer a, String b) { (self) -> void } -> void
end

When I use runtime type-checking via rbs test using smth like B.new(1, "a") { |b| puts b }, I get an error similar to:

RuntimeError: Neutered Exception RBS::Test::Tester::TypeError: TypeError: [B#initialize] ArgumentTypeError: expected `String` (b) but given `1`

Where the first argument is being incorrectly passed the second argumet type def.

I can workaround that now by doing the block-based definition on A's rbs file, which is wrong, but it at least fixes it.

HoneyryderChuck avatar Sep 04 '23 09:09 HoneyryderChuck