Skip to content

Tell super outside a method from super in a define_method block - #497

Merged
mame merged 2 commits into
ruby:masterfrom
mame:fix-super-outside-method-diag
Sep 28, 2026
Merged

mame merged 2 commits into
ruby:masterfrom
mame:fix-super-outside-method-diag

Conversation

@mame

@mame mame commented Sep 28, 2026

Copy link
Copy Markdown
Member

Follow-up to #484.

super without a method now reports Ruby's own wording:

  • At the top level, in a class body, or in a block there: super called outside of method, for both super and super(). Before, super() reported nothing.
  • A bare super in a define_method block: implicit argument passing of super from method defined by define_method() is not supported.

To tell these apart, CRef now records whether it is inside a method body. A define_method block counts as one even though its method name is unknown.

This also fixes ... in a define_method block. The block had dropped the enclosing method's forwarded arguments in order to reject a bare super, so ... there reported the super diagnostic:

def self.m(...)
  define_method(:x) { pr(...) }  # no longer reported
end

mame and others added 2 commits September 28, 2026 20:36
A bare `super` without enclosing method arguments reported "implicit
argument passing of super is not supported here" wherever it was, and
`super()` outside a method reported nothing. Ruby raises "super called
outside of method" at the top level, in a class body and in a block
there, and rejects only the bare `super` in a define_method block.

CRef now records whether it is inside a method body, which a
define_method block is although its method name is unknown, so the two
cases are reported with Ruby's wording.

This also lets a define_method block keep the enclosing method's
forward_args, which it had dropped to reject a bare `super`, so `...`
in the block no longer reports the super diagnostic:

    def self.m(...)
      define_method(:x) { pr(...) }
    end

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mame
mame enabled auto-merge (rebase) September 28, 2026 13:24
@mame
mame merged commit ab1bf4b into ruby:master Sep 28, 2026
6 checks passed
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