Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

paracycle
Copy link
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.

@paracycle paracycle force-pushed the uk-ampersand-nil branch 3 times, most recently from ede6a34 to 67487ef Compare July 6, 2024 11:58
nobu and others added 3 commits July 7, 2024 19:39
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.
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.

4 participants