Report super outside a method instead of crashing - #484
Open
sinsoku wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation / Background
This Pull Request has been created because a bare
superthat has no enclosing method definition aborts the analysis with a RuntimeError that carries no message: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 thatlenv.forward_argsis missing.The call still goes through method resolution afterwards, where a bare
superfalls back tocref.midfor its method name, so a second diagnostic such asundefined method: Object#define_methodlands on the same range. The crash used to hide that misattribution; suppressing it needs a separate change.🤖 Generated with Claude Code