diff --git a/Library/Homebrew/cask/config.rb b/Library/Homebrew/cask/config.rb index c99ac319da..db28860126 100644 --- a/Library/Homebrew/cask/config.rb +++ b/Library/Homebrew/cask/config.rb @@ -169,10 +169,12 @@ module Cask DEFAULT_DIRS.each_key do |dir| define_method(dir) do + T.bind(self, Config) explicit.fetch(dir, env.fetch(dir, default.fetch(dir))) end define_method(:"#{dir}=") do |path| + T.bind(self, Config) explicit[dir] = Pathname(path).expand_path end end diff --git a/Library/Homebrew/cask/dsl.rb b/Library/Homebrew/cask/dsl.rb index 461b87af5b..86084afd07 100644 --- a/Library/Homebrew/cask/dsl.rb +++ b/Library/Homebrew/cask/dsl.rb @@ -339,6 +339,7 @@ module Cask ORDINARY_ARTIFACT_CLASSES.each do |klass| define_method(klass.dsl_key) do |*args, **kwargs| + T.bind(self, DSL) if [*artifacts.map(&:class), klass].include?(Artifact::StageOnly) && (artifacts.map(&:class) & ACTIVATABLE_ARTIFACT_CLASSES).any? raise CaskInvalidError.new(cask, "'stage_only' must be the only activatable artifact.") @@ -355,6 +356,7 @@ module Cask ARTIFACT_BLOCK_CLASSES.each do |klass| [klass.dsl_key, klass.uninstall_dsl_key].each do |dsl_key| define_method(dsl_key) do |&block| + T.bind(self, DSL) artifacts.add(klass.new(cask, dsl_key => block)) end end diff --git a/Library/Homebrew/cask/dsl/version.rb b/Library/Homebrew/cask/dsl/version.rb index bb02439dbf..2b5170406b 100644 --- a/Library/Homebrew/cask/dsl/version.rb +++ b/Library/Homebrew/cask/dsl/version.rb @@ -32,6 +32,7 @@ module Cask def define_divider_deletion_method(divider) method_name = deletion_method_name(divider) define_method(method_name) do + T.bind(self, Version) version { delete(divider) } end end @@ -49,6 +50,7 @@ module Cask def define_divider_conversion_method(left_divider, right_divider) method_name = conversion_method_name(left_divider, right_divider) define_method(method_name) do + T.bind(self, Version) version { gsub(left_divider, right_divider) } end end diff --git a/Library/Homebrew/extend/on_system.rb b/Library/Homebrew/extend/on_system.rb index ccd923df4d..5d4c581f44 100644 --- a/Library/Homebrew/extend/on_system.rb +++ b/Library/Homebrew/extend/on_system.rb @@ -1,4 +1,4 @@ -# typed: false +# typed: true # frozen_string_literal: true require "simulate_system" @@ -9,17 +9,15 @@ module OnSystem ARCH_OPTIONS = [:intel, :arm].freeze BASE_OS_OPTIONS = [:macos, :linux].freeze - module_function - sig { params(arch: Symbol).returns(T::Boolean) } - def arch_condition_met?(arch) + def self.arch_condition_met?(arch) raise ArgumentError, "Invalid arch condition: #{arch.inspect}" if ARCH_OPTIONS.exclude?(arch) arch == Homebrew::SimulateSystem.current_arch end sig { params(os_name: Symbol, or_condition: T.nilable(Symbol)).returns(T::Boolean) } - def os_condition_met?(os_name, or_condition = nil) + def self.os_condition_met?(os_name, or_condition = nil) return Homebrew::SimulateSystem.send("simulating_or_running_on_#{os_name}?") if BASE_OS_OPTIONS.include?(os_name) raise ArgumentError, "Invalid OS condition: #{os_name.inspect}" unless MacOSVersions::SYMBOLS.key?(os_name) @@ -46,17 +44,17 @@ module OnSystem end sig { params(method_name: Symbol).returns(Symbol) } - def condition_from_method_name(method_name) + def self.condition_from_method_name(method_name) method_name.to_s.sub(/^on_/, "").to_sym end sig { params(base: Class).void } - def setup_arch_methods(base) + def self.setup_arch_methods(base) ARCH_OPTIONS.each do |arch| base.define_method("on_#{arch}") do |&block| @on_system_blocks_exist = true - return unless OnSystem.arch_condition_met? OnSystem.condition_from_method_name(__method__) + return unless OnSystem.arch_condition_met? OnSystem.condition_from_method_name(T.must(__method__)) @called_in_on_system_block = true result = block.call @@ -75,12 +73,12 @@ module OnSystem end sig { params(base: Class).void } - def setup_base_os_methods(base) + def self.setup_base_os_methods(base) BASE_OS_OPTIONS.each do |base_os| base.define_method("on_#{base_os}") do |&block| @on_system_blocks_exist = true - return unless OnSystem.os_condition_met? OnSystem.condition_from_method_name(__method__) + return unless OnSystem.os_condition_met? OnSystem.condition_from_method_name(T.must(__method__)) @called_in_on_system_block = true result = block.call @@ -118,12 +116,12 @@ module OnSystem end sig { params(base: Class).void } - def setup_macos_methods(base) + def self.setup_macos_methods(base) MacOSVersions::SYMBOLS.each_key do |os_name| base.define_method("on_#{os_name}") do |or_condition = nil, &block| @on_system_blocks_exist = true - os_condition = OnSystem.condition_from_method_name __method__ + os_condition = OnSystem.condition_from_method_name T.must(__method__) return unless OnSystem.os_condition_met? os_condition, or_condition @called_in_on_system_block = true diff --git a/Library/Homebrew/sorbet/rbi/upstream.rbi b/Library/Homebrew/sorbet/rbi/upstream.rbi deleted file mode 100644 index dbade1d0dc..0000000000 --- a/Library/Homebrew/sorbet/rbi/upstream.rbi +++ /dev/null @@ -1,23 +0,0 @@ -# typed: strict - -# This file contains temporary definitions for fixes that have -# been submitted upstream to https://github.com/sorbet/sorbet. - -class Module - # https://github.com/sorbet/sorbet/pull/3732 - sig do - params( - arg0: T.any(Symbol, String), - arg1: T.any(Proc, Method, UnboundMethod) - ) - .returns(Symbol) - end - sig do - params( - arg0: T.any(Symbol, String), - blk: T.proc.bind(T.untyped).returns(T.untyped), - ) - .returns(Symbol) - end - def define_method(arg0, arg1=T.unsafe(nil), &blk); end -end