Skip to content

Requirement #which override incompatible with Kernel #which signature #22036

@htrungngx

Description

@htrungngx

brew doctor output

brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!

Warning: Found Ruby file outside smartlyio/devbox tap formula directory.
(/opt/homebrew/Library/Taps/smartlyio/homebrew-devbox/Formula):
  /opt/homebrew/Library/Taps/smartlyio/homebrew-devbox/openssl@3.rb

Warning: Broken symlinks were found. Remove them with `brew cleanup`:
  /opt/homebrew/bin/trackweight

Verification

  • I ran brew update twice and am still able to reproduce my issue.
  • My "brew doctor output" above says Your system is ready to brew or a definitely unrelated Tier message.
  • This issue's title and/or description do not reference a single formula e.g. brew install wget. If they do, open an issue at https://github.com/Homebrew/homebrew-core/issues/new/choose instead.

brew config output

brew config
HOMEBREW_VERSION: 5.1.6-89-g598ecb7
ORIGIN: https://github.com/Homebrew/brew
HEAD: 598ecb7ce3b6ad3ba39e8e51cf1bc53c62388354
Last commit: 14 hours ago
Branch: main
Core tap JSON: 17 Apr 07:49 UTC
Core cask tap JSON: 17 Apr 07:49 UTC
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_CASK_OPTS: []
HOMEBREW_DOWNLOAD_CONCURRENCY: 24
HOMEBREW_FORBID_PACKAGES_FROM_PATHS: set
HOMEBREW_MAKE_JOBS: 12
HOMEBREW_SORBET_RUNTIME: set
Homebrew Ruby: 4.0.2 => /opt/homebrew/Library/Homebrew/vendor/portable-ruby/4.0.2_1/bin/ruby
CPU: dodeca-core 64-bit arm_lobos
Clang: 21.0.0 build 2100
Git: 2.53.0 => /opt/homebrew/bin/git
Curl: 8.7.1 => /usr/bin/curl
macOS: 26.3.1-arm64
CLT: N/A
Xcode: 26.4
Metal Toolchain: N/A
Rosetta 2: false

What were you trying to do (and why)?

Running brew to fetch downloads for a custom tap formula (devbox)

==> Fetching downloads for: devbox
Error: Your definition of `which` must accept at least 2 positional arguments to be compatible with the method it overrides: 
 * Base definition: in Kernel at /opt/homebrew/Library/Homebrew/extend/kernel.rb:90
 * Override: in Requirement at /opt/homebrew/Library/Homebrew/requirement.rb:204

What happened (include all command output)?

The Requirement #which override only accepts 1 positional argument, but the base Kernel #which accepts 2 positional arguments.

Ruby's method override compatibility check rejects this because the override has a narrower signature.

What did you expect to happen?

The command should complete successfully. The Requirement #which override should be compatible with the Kernel #which base method signature.

Base method

##/opt/homebrew/Library/Homebrew/extend/kernel.rb
  sig { params(cmd: String, path: PATH::Elements).returns(T.nilable(Pathname)) }
  def which(cmd, path = ENV.fetch("PATH"))

Override

##/opt/homebrew/Library/Homebrew/requirement.rb
  sig { params(cmd: String).returns(T.nilable(Pathname)) }
  def which(cmd)
    super(cmd, PATH.new(ORIGINAL_PATHS))
  end

Should be

##/opt/homebrew/Library/Homebrew/requirement.rb
  sig { params(cmd: String, path: PATH::Elements).returns(T.nilable(Pathname)) }
  def which(cmd, path = PATH.new(ORIGINAL_PATHS))
    super(cmd, path)
  end

Step-by-step reproduction instructions (by running brew commands)

cat > /tmp/test_which_requirement.rb <<'RUBY'
require "requirement"

class TestWhichRequirement < Requirement
  fatal true
  satisfy(build_env: false) { which("git") }
end
RUBY

brew ruby -r /tmp/test_which_requirement -e "req = TestWhichRequirement.new; puts req.satisfied?"

output:

/opt/homebrew/Library/Homebrew/vendor/bundle/ruby/4.0.0/gems/sorbet-runtime-0.6.13114/lib/types/private/methods/signature_validation.rb:186:in 'T::Private::Methods::SignatureValidation.validate_override_shape': Your definition of `which` must accept at least 2 positional arguments to be compatible with the method it overrides:  (RuntimeError)
 * Base definition: in Kernel at /opt/homebrew/Library/Homebrew/extend/kernel.rb:90
 * Override: in Requirement at /opt/homebrew/Library/Homebrew/requirement.rb:204

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions