From e1aae25fd20707ebee2e680dee46ef5bf4a1da77 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Fri, 5 Sep 2025 19:31:34 -0700 Subject: [PATCH] Deep typecheck arrays in specs --- Library/Homebrew/PATH.rb | 2 +- Library/Homebrew/cli/args.rb | 2 +- Library/Homebrew/test/dev-cmd/bottle_spec.rb | 4 ++-- Library/Homebrew/test/formula_spec.rb | 2 +- Library/Homebrew/test/spec_helper.rb | 11 +++++++++++ Library/Homebrew/utils/inreplace.rb | 2 +- 6 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/PATH.rb b/Library/Homebrew/PATH.rb index 0aea775d98..90da11abe9 100644 --- a/Library/Homebrew/PATH.rb +++ b/Library/Homebrew/PATH.rb @@ -12,7 +12,7 @@ class PATH delegate each: :@paths Elem = type_member(:out) { { fixed: String } } - Element = T.type_alias { T.nilable(T.any(Pathname, String, PATH)) } + Element = T.type_alias { T.any(NilClass, Pathname, String, PATH) } private_constant :Element Elements = T.type_alias { T.any(Element, T::Array[Element]) } sig { params(paths: Elements).void } diff --git a/Library/Homebrew/cli/args.rb b/Library/Homebrew/cli/args.rb index f3358bfc10..f57044dc3a 100644 --- a/Library/Homebrew/cli/args.rb +++ b/Library/Homebrew/cli/args.rb @@ -9,7 +9,7 @@ module Homebrew # 1: long option name (e.g. "--debug") # 2: option description (e.g. "Print debugging information") # 3: whether the option is hidden - OptionsType = T.type_alias { T::Array[[String, T.nilable(String), String, T::Boolean]] } + OptionsType = T.type_alias { T::Array[[T.nilable(String), T.nilable(String), String, T::Boolean]] } sig { returns(T::Array[String]) } attr_reader :options_only, :flags_only, :remaining diff --git a/Library/Homebrew/test/dev-cmd/bottle_spec.rb b/Library/Homebrew/test/dev-cmd/bottle_spec.rb index 5b76df2bc2..76fd83778b 100644 --- a/Library/Homebrew/test/dev-cmd/bottle_spec.rb +++ b/Library/Homebrew/test/dev-cmd/bottle_spec.rb @@ -430,7 +430,7 @@ RSpec.describe Homebrew::DevCmd::Bottle do old_spec = BottleSpecification.new old_spec.root_url("https://failbrew.bintray.com/bottles") new_hash = { "root_url" => "https://testbrew.bintray.com/bottles" } - expect(homebrew.merge_bottle_spec([:root_url], old_spec, new_hash)).to eq [ + expect(homebrew.merge_bottle_spec(["root_url"], old_spec, new_hash)).to eq [ ['root_url: old: "https://failbrew.bintray.com/bottles", new: "https://testbrew.bintray.com/bottles"'], [], ] @@ -440,7 +440,7 @@ RSpec.describe Homebrew::DevCmd::Bottle do old_spec = BottleSpecification.new old_spec.rebuild(1) new_hash = { "rebuild" => 2 } - expect(homebrew.merge_bottle_spec([:rebuild], old_spec, new_hash)).to eq [ + expect(homebrew.merge_bottle_spec(["rebuild"], old_spec, new_hash)).to eq [ ['rebuild: old: "1", new: "2"'], [], ] diff --git a/Library/Homebrew/test/formula_spec.rb b/Library/Homebrew/test/formula_spec.rb index 9925d05ce6..6eefa7b2dc 100644 --- a/Library/Homebrew/test/formula_spec.rb +++ b/Library/Homebrew/test/formula_spec.rb @@ -919,7 +919,7 @@ RSpec.describe Formula do f1 = formula "f1" do url "f1-1" - depends_on xcode: ["1.0", :optional] + depends_on xcode: ["1.0", "optional"] end stub_formula_loader(f1) diff --git a/Library/Homebrew/test/spec_helper.rb b/Library/Homebrew/test/spec_helper.rb index 8bf8ea63d0..61246fc0d1 100644 --- a/Library/Homebrew/test/spec_helper.rb +++ b/Library/Homebrew/test/spec_helper.rb @@ -25,6 +25,17 @@ end require_relative "../standalone" require_relative "../warnings" +module T + module Types + class TypedArray < TypedEnumerable + # overrides Base + def valid?(obj) + recursively_valid?(obj) + end + end + end +end + Warnings.ignore :parser_syntax do require "rubocop" end diff --git a/Library/Homebrew/utils/inreplace.rb b/Library/Homebrew/utils/inreplace.rb index 360b90be72..1c082144c9 100644 --- a/Library/Homebrew/utils/inreplace.rb +++ b/Library/Homebrew/utils/inreplace.rb @@ -86,7 +86,7 @@ module Utils sig { params( path: T.any(String, Pathname), - replacement_pairs: T::Array[[T.any(Regexp, Pathname, String), T.any(Pathname, String)]], + replacement_pairs: T::Array[[T.any(NilClass, Regexp, Pathname, String), T.any(Pathname, String)]], read_only_run: T::Boolean, silent: T::Boolean, ).returns(String)