ruby / ruby/rbs

[RBS::Test] Cannot call `super` in block

Open
#1,716 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

I have found a case where test fails to call super in a block during RBS::Test execution.

Repro:

#! /usr/bin/env ruby

class Super
  def call
    'super'
  end
end

class Sample
  def initialize
    @handlers = []
  end

  def handler(&block)
    @handlers << Class.new(Super) { define_method(:call, &block) }
  end

  def call
    @handlers.map { |h| h.new.call }
  end
end

sample = Sample.new
sample.handler do
  p super()
end
sample.call
# handler.rbs
class Sample
  def handler: () { () -> void } -> void
end
$ ruby handler.rb
"super"
$ RUBYOPT="-r rbs/test/setup" RBS_TEST_OPT="-I handler.rbs" RBS_TEST_TARGET="Sample" ruby handler.rb
I, [2024-01-10T16:01:48.008226 #87538]  INFO -- : Setting up hooks for ::Sample
I, [2024-01-10T16:01:48.008271 #87538]  INFO -- rbs: Installing runtime type checker in Sample...
I, [2024-01-10T16:01:48.011547 #87538]  INFO -- rbs: Setting up method hook in #handler...
handler.rb:25:in `block in <main>': super called outside of method (NoMethodError)
	from /Users/ksss.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/rbs-3.4.0/lib/rbs/test/hook.rb:113:in `instance_exec'
	from /Users/ksss/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/rbs-3.4.0/lib/rbs/test/hook.rb:113:in `block in handler__with__RBS_TEST_20215d_84415718'
	from handler.rb:19:in `block in call'
	from handler.rb:19:in `map'
	from handler.rb:19:in `call'
	from handler.rb:27:in `<main>'

Real case: https://github.com/aws/aws-sdk-ruby/blob/b501a7f87aaf78f12667de2c436f4f6463fe6af9/gems/aws-sdk-core/spec/seahorse/client/handler_builder_spec.rb#L52-L55

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 with the handler.rb reproduction and the failing path reported at lib/rbs/test/hook.rb:113, focusing on how RBS::Test invokes the handler block. Run the example with the supplied RBS_TEST setup and confirm that super() works as it does without the checker, including the real aws-sdk-ruby handler_builder_spec.rb case.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.