Accept block-pass arguments for optional blocks - #2261
Merged
Conversation
soutaro
commented
Aug 13, 2026
`&:sym` and `&method(:name)` failed to type check when the method
declares an optional block:
```
test.rb:1:13: [error] Cannot pass a value of type `::Proc` as a block-pass-argument of type `(^(::Integer) -> void | nil)`
│ ::Proc <: (^(::Integer) -> void | nil)
│ ::Proc <: ^(::Integer) -> void
│
│ Diagnostic ID: Ruby::BlockTypeMismatch
│
└ Foo.new.each(&:to_s)
~~~~~~
```
Both are special cased in `:block_pass` so that `Symbol#to_proc` and
`Method#to_proc` are given a proc type built from the expected block
type. The special cases match on `AST::Types::Proc`, but the hint of a
block-pass argument is `^(...) -> ... | nil` when the block is optional,
so neither applied and the argument kept the plain `::Proc` type it
converts to.
Hint the argument with the block type itself instead of the union.
`BlockPassArg` builds both, so it exposes `proc_type` next to
`node_type`, and the union stays where it belongs -- the subtyping check
that lets `nil` through for an optional block.
Fixes #1207
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Nx2PCA7ngK5EZkgNtHM5b6
soutaro
force-pushed
the
claude/steep-fix-review-b9qpec
branch
from
August 13, 2026 15:06
0b6644e to
9970cb5
Compare
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.
Fixes #1207.
&:symand&method(:name)fail against an optional block:The
Symbol#to_proc/Method#to_procspecial cases in:block_passmatch onAST::Types::Proc, but the hint of a block-pass argument is^(...) -> ... | nilwhen the block is optional, so neither runs and the argument keeps the plain::Procit converts to.Fixed by hinting the argument with the block type itself.
BlockPassArgbuilds both, so it exposesproc_typenext tonode_type, and the union stays where it belongs — the subtyping check that letsnilthrough for an optional block.This removes the need for ruby/rbs#3060.