From 9c64f700851013b70a1b31ca7803a78ec8295d97 Mon Sep 17 00:00:00 2001 From: mybys Date: Mon, 3 Aug 2026 10:22:19 +0900 Subject: [PATCH] Restore blockless overloads for optional-block methods `Array#sum`, `Array#count` and `Hash#transform_keys!` were changed to use optional blocks (`?{ ... }`) in 4.1. Steep cannot check a block-pass argument against an optional block: the expected type becomes a union with `nil`, which the special case for `Proc` values does not cover (soutaro/steep#1207). As a result `array.sum(&:amount)`, `array.count(&:even?)` and friends stopped type checking after 4.0.3, even though the same call with a literal block is fine. Spell out the blockless overload again so that block-pass arguments match the overload with a required block, as they did before. Co-Authored-By: Claude Opus 5 --- core/array.rbs | 6 ++++-- core/hash.rbs | 3 ++- test/typecheck/block_pass/Steepfile | 7 +++++++ test/typecheck/block_pass/test.rb | 11 +++++++++++ 4 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 test/typecheck/block_pass/Steepfile create mode 100644 test/typecheck/block_pass/test.rb diff --git a/core/array.rbs b/core/array.rbs index 000dba738a..80ab7ed5a9 100644 --- a/core/array.rbs +++ b/core/array.rbs @@ -1427,7 +1427,8 @@ class Array[unchecked out E] # # Related: see [Methods for Querying](rdoc-ref:Array@Methods+for+Querying). # - def count: () ?{ (E element) -> boolish } -> Integer + def count: () -> Integer + | () { (E element) -> boolish } -> Integer | (untyped object) -> Integer # where E: RBS::Ops::_Equal #