diff --git a/Library/Homebrew/cask/dsl/depends_on.rb b/Library/Homebrew/cask/dsl/depends_on.rb index 7a5756f9c0..4e08bb8932 100644 --- a/Library/Homebrew/cask/dsl/depends_on.rb +++ b/Library/Homebrew/cask/dsl/depends_on.rb @@ -60,9 +60,9 @@ module Cask elsif MacOSVersion::SYMBOLS.key?(args.first) MacOSRequirement.new([args.first], comparator: "==") elsif (md = /^\s*(?<|>|[=<>]=)\s*:(?\S+)\s*$/.match(first_arg)) - MacOSRequirement.new([T.must(md[:version]).to_sym], comparator: md[:comparator]) + MacOSRequirement.new([T.must(md[:version]).to_sym], comparator: T.must(md[:comparator])) elsif (md = /^\s*(?<|>|[=<>]=)\s*(?\S+)\s*$/.match(first_arg)) - MacOSRequirement.new([md[:version]], comparator: md[:comparator]) + MacOSRequirement.new([md[:version]], comparator: T.must(md[:comparator])) # This is not duplicate of the first case: see `args.first` and a different comparator. else # rubocop:disable Lint/DuplicateBranch MacOSRequirement.new([args.first], comparator: "==") diff --git a/Library/Homebrew/requirements/macos_requirement.rb b/Library/Homebrew/requirements/macos_requirement.rb index 9b0be0d8d3..4624349739 100644 --- a/Library/Homebrew/requirements/macos_requirement.rb +++ b/Library/Homebrew/requirements/macos_requirement.rb @@ -7,14 +7,17 @@ require "requirement" class MacOSRequirement < Requirement fatal true - attr_reader :comparator, :version + sig { returns(String) } + attr_reader :comparator + + attr_reader :version # TODO: when Yosemite is removed here, keep these around as empty arrays so we # can keep the deprecation/disabling code the same. - DISABLED_MACOS_VERSIONS = [ + DISABLED_MACOS_VERSIONS = T.let([ :yosemite, - ].freeze - DEPRECATED_MACOS_VERSIONS = [].freeze + ].freeze, T::Array[Symbol]) + DEPRECATED_MACOS_VERSIONS = T.let([].freeze, T::Array[Symbol]) def initialize(tags = [], comparator: ">=") @version = begin @@ -44,10 +47,11 @@ class MacOSRequirement < Requirement MacOSVersion.new(HOMEBREW_MACOS_OLDEST_ALLOWED) if comparator == ">=" end - @comparator = comparator + @comparator = T.let(comparator, String) super(tags.drop(1)) end + sig { returns(T::Boolean) } def version_specified? @version.present? end @@ -61,6 +65,7 @@ class MacOSRequirement < Requirement false end + sig { returns(MacOSVersion) } def minimum_version return MacOSVersion.new(HOMEBREW_MACOS_OLDEST_ALLOWED) if @comparator == "<=" || !version_specified? return @version.min if @version.respond_to?(:to_ary) @@ -68,6 +73,7 @@ class MacOSRequirement < Requirement @version end + sig { returns(MacOSVersion) } def maximum_version return MacOSVersion.new(HOMEBREW_MACOS_NEWEST_UNSUPPORTED) if @comparator == ">=" || !version_specified? return @version.max if @version.respond_to?(:to_ary) @@ -75,6 +81,7 @@ class MacOSRequirement < Requirement @version end + sig { params(other: MacOSVersion).returns(T::Boolean) } def allows?(other) return true unless version_specified? @@ -98,6 +105,7 @@ class MacOSRequirement < Requirement end end + sig { params(type: Symbol).returns(String) } def message(type: :formula) return "macOS is required for this software." unless version_specified? @@ -113,6 +121,8 @@ class MacOSRequirement < Requirement EOS when :cask "This cask does not run on macOS versions newer than #{@version.pretty_name}." + else + "This does not run on macOS versions newer than #{@version.pretty_name}." end else if @version.respond_to?(:to_ary) @@ -129,6 +139,7 @@ class MacOSRequirement < Requirement end alias eql? == + sig { returns(Integer) } def hash [super, comparator, version].hash end @@ -151,6 +162,7 @@ class MacOSRequirement < Requirement end end + sig { params(options: T.untyped).returns(String) } def to_json(options) comp = @comparator.to_s return { comp => @version.map(&:to_s) }.to_json(options) if @version.is_a?(Array)