Skip to content

Report super outside a method instead of crashing - #484

Open
sinsoku wants to merge 1 commit into
ruby:masterfrom
sinsoku:report-super-outside-method
Open

Report super outside a method instead of crashing#484
sinsoku wants to merge 1 commit into
ruby:masterfrom
sinsoku:report-super-outside-method

Conversation

@sinsoku

@sinsoku sinsoku commented Sep 12, 2026

Copy link
Copy Markdown
Collaborator

Motivation / Background

This Pull Request has been created because a bare super that has no enclosing method definition aborts the analysis with a RuntimeError that carries no message:

define_method(:foo) do |x|
  super
end
#=> unhandled exception

ruby/ruby hits this in spec/ruby/language/super_spec.rb, which asserts that Ruby raises there at run time, so it deserves a diagnostic rather than a crash.

Detail

The message does not quote Ruby's own, because that differs by context: a RuntimeError about implicit argument passing from define_method, and "super called outside of method" at the top level or in a class body. TypeProf only knows that lenv.forward_args is missing.

The call still goes through method resolution afterwards, where a bare super falls back to cref.mid for its method name, so a second diagnostic such as undefined method: Object#define_method lands on the same range. The crash used to hide that misattribution; suppressing it needs a separate change.

🤖 Generated with Claude Code

Only a method definition sets lenv.forward_args, which a bare `super`
shares with `...` forwarding, so `define_method(:foo) { |x| super }` ran
a bare `raise` and surfaced as a RuntimeError with no message. Report a
diagnostic instead and treat the call as taking no arguments. Ruby's own
wording differs by context, an implicit argument passing error from
define_method and "super called outside of method" at the top level, and
TypeProf only knows that forward_args is missing, so the message quotes
neither.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant