Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rbs/test: stack level too deep when calling super from prepend #1710

Open
larskanis opened this issue Jan 5, 2024 · 1 comment
Open

rbs/test: stack level too deep when calling super from prepend #1710

larskanis opened this issue Jan 5, 2024 · 1 comment

Comments

@larskanis
Copy link

Similar issue to #478 .

Example:

# test-attach.rb
class TestAttach
  def attach
    puts "attach 2"
  end

  module RegisterAttach
    def attach
      puts "attach 1"
      super
    end
  end
  prepend RegisterAttach
end

TestAttach.new.attach
# sig/test-attach.rbs
class TestAttach
  def attach: () -> String
end

Run without rbs/test is OK:

$ ruby test-attach.rb 
attach 1
attach 2

Run with rbs/test fails with stack level too deep:

$ RBS_TEST_TARGET='TestAttach' ruby -r rbs/test/setup test-attach.rb 
[...]
attach 1
attach 1
/home/lars/.rvm/gems/ruby-3.3.0/gems/rbs-3.4.1/lib/rbs/test/type_check.rb:60:in `method_call': stack level too deep (SystemStackError)
	from /home/lars/.rvm/gems/ruby-3.3.0/gems/rbs-3.4.1/lib/rbs/test/type_check.rb:26:in `block in overloaded_call'
	from /home/lars/.rvm/gems/ruby-3.3.0/gems/rbs-3.4.1/lib/rbs/test/type_check.rb:25:in `map'
	from /home/lars/.rvm/gems/ruby-3.3.0/gems/rbs-3.4.1/lib/rbs/test/type_check.rb:25:in `overloaded_call'
	from /home/lars/.rvm/gems/ruby-3.3.0/gems/rbs-3.4.1/lib/rbs/test/tester.rb:152:in `call'
	from /home/lars/.rvm/gems/ruby-3.3.0/gems/rbs-3.4.1/lib/rbs/test/observer.rb:10:in `notify'
	from /home/lars/.rvm/gems/ruby-3.3.0/gems/rbs-3.4.1/lib/rbs/test/hook.rb:178:in `ensure in attach__with__RBS_TEST_16c021_404c48f8'
	from /home/lars/.rvm/gems/ruby-3.3.0/gems/rbs-3.4.1/lib/rbs/test/hook.rb:178:in `attach__with__RBS_TEST_16c021_404c48f8'
	from test-attach.rb:9:in `attach'
	 ... 7697 levels...
	from test-attach.rb:9:in `attach'
	from /home/lars/.rvm/gems/ruby-3.3.0/gems/rbs-3.4.1/lib/rbs/test/hook.rb:146:in `attach__with__RBS_TEST_16c021_404c48f8'
	from test-attach.rb:9:in `attach'
	from test-attach.rb:15:in `<main>'
@ksss
Copy link
Collaborator

ksss commented Jan 8, 2024

To simplify the problem, it appears that the hook is adding methods as follows, resulting in an infinite loop.

# test-attach.rb
class TestAttach
  def attach
    puts "attach 2"
  end

  module RegisterAttach
    def attach
      puts "attach 1"
      super
    end
  end
  prepend RegisterAttach

  # append by hook
  def with_attach
    send(:without_attach)
  end
  alias without_attach attach
  alias attach with_attach
end

TestAttach.new.attach

To solve the problem, the structure of the hook may need to be changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants