[Feature #19979] Method definition with &nil#11065
Merged
kddnewton merged 3 commits intoruby:masterfrom Feb 15, 2026
Merged
Conversation
jeremyevans
reviewed
Jun 26, 2024
67487ef to
530388d
Compare
Contributor
|
Feature was accepted by Matz in a dev meeting, so this PR probably should be updated. |
37b680b to
6ace423
Compare
Contributor
Author
|
@kddnewton I've rebased this and made the changes you asked for. It should be ready for your review. 🙏 |
Contributor
|
@paracycle looks like there's a zjit thing that needs fixing, then it's good |
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.
6ace423 to
aac53af
Compare
Contributor
Author
Thanks! I applied the patch from the failing job and force-pushed the changes. |
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>
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.
This PR pushes the original work done by @nobu in #10020 (thank you 🙏) and reworks it slightly along two directions:
accepts_no_block(similar toaccepts_no_kwarg) and decouples the handling of&nilfrom theuse_blockflag which is used for detection for methods that don't make use of the blocks that are passed to them.use_blockshould 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 asuse_block == FALSEwill be a warning.accepts_no_blockflag as:noblockin theMethod#parameters,UnboundMethod#parametersandProc#parametersresult arrays. This is inline with**nildeclaration surfacing inparametersas:nokey, and allows method introspection to detect if a method declares that it definitely does NOT accept a block.