Skip to content

[Feature #19979] Method definition with &nil#11065

Merged
kddnewton merged 3 commits intoruby:masterfrom
Shopify:uk-ampersand-nil
Feb 15, 2026
Merged

[Feature #19979] Method definition with &nil#11065
kddnewton merged 3 commits intoruby:masterfrom
Shopify:uk-ampersand-nil

Conversation

@paracycle
Copy link
Copy Markdown
Contributor

This PR pushes the original work done by @nobu in #10020 (thank you 🙏) and reworks it slightly along two directions:

  1. This PR introduces a new iseq flag named accepts_no_block (similar to accepts_no_kwarg) and decouples the handling of &nil from the use_block flag which is used for detection for methods that don't make use of the blocks that are passed to them. use_block should NOT mean the same thing as &nil, since the latter is an explicit declaration that the method definitely does NOT accept a block, so passing a block should be an error. On the other hand, passing a block to an iseq marked as use_block == FALSE will be a warning.
  2. This PR also adds support for exposing the accepts_no_block flag as :noblock in the Method#parameters, UnboundMethod#parameters and Proc#parameters result arrays. This is inline with **nil declaration surfacing in parameters as :nokey, and allows method introspection to detect if a method declares that it definitely does NOT accept a block.

Comment thread spec/ruby/core/method/parameters_spec.rb Outdated
@paracycle paracycle force-pushed the uk-ampersand-nil branch 4 times, most recently from 67487ef to 530388d Compare July 7, 2024 16:39
@trinistr
Copy link
Copy Markdown
Contributor

trinistr commented Feb 7, 2026

Feature was accepted by Matz in a dev meeting, so this PR probably should be updated.
(Have been waiting for this feature for a while now 😓)

@paracycle paracycle force-pushed the uk-ampersand-nil branch 2 times, most recently from 37b680b to 6ace423 Compare February 15, 2026 17:26
@paracycle
Copy link
Copy Markdown
Contributor Author

@kddnewton I've rebased this and made the changes you asked for. It should be ready for your review. 🙏

@kddnewton
Copy link
Copy Markdown
Contributor

@paracycle looks like there's a zjit thing that needs fixing, then it's good

nobu and others added 3 commits February 15, 2026 20:32
Allow methods to declare that they don't accept a block via `&nil`.
Similar to `:nokey` for `**nil` declaring methods/procs, a method/proc with a `&nil` declaration will return a `:noblock` entry in the parameters array.
@paracycle
Copy link
Copy Markdown
Contributor Author

@paracycle looks like there's a zjit thing that needs fixing, then it's good

Thanks! I applied the patch from the failing job and force-pushed the changes.

@kddnewton kddnewton merged commit 9967418 into ruby:master Feb 15, 2026
92 checks passed
Earlopain added a commit to Earlopain/prism that referenced this pull request Feb 16, 2026
ruby/ruby#11065
https://bugs.ruby-lang.org/issues/19979

Co-authored-by: Ufuk Kayserilioglu <ufuk.kayserilioglu@shopify.com>
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.

6 participants