rbs icon indicating copy to clipboard operation
rbs copied to clipboard

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

Open ksss opened this issue 1 year ago • 0 comments

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

ksss avatar Jan 10 '24 07:01 ksss