ruby / ruby/rbs

override a function with a block fails

Open
#1,497 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Ruby
Stars
2.2k
Forks
256
Avg merge
6d 17h
Merged PRs (30d)
37

Description

  • 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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported failure with the Ruby and RBS snippets using rbs test. Trace how runtime checking handles an overridden initialize method with a block, then verify that B.new(1, "a") checks the first argument as Integer, the second as String, and the block without swapping types.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.