diff --git a/Library/Homebrew/debrew.rb b/Library/Homebrew/debrew.rb index 53f2e3d51f..661d9e7428 100644 --- a/Library/Homebrew/debrew.rb +++ b/Library/Homebrew/debrew.rb @@ -1,4 +1,4 @@ -# typed: false +# typed: true # frozen_string_literal: true require "mutex_m" @@ -47,7 +47,7 @@ module Debrew menu = new yield menu - choice = nil + choice = T.let(nil, T.nilable(Entry)) while choice.nil? menu.entries.each_with_index { |e, i| puts "#{i + 1}. #{e.name}" } print menu.prompt unless menu.prompt.nil? @@ -90,7 +90,7 @@ module Debrew yield rescue SystemExit raise - rescue Exception => e # rubocop:disable Lint/RescueException + rescue Ignorable::ExceptionMixin => e e.ignore if debug(e) == :ignore # execution jumps back to where the exception was thrown ensure Ignorable.unhook_raise @@ -99,7 +99,7 @@ module Debrew end def self.debug(exception) - raise(exception) if !active? || !debugged_exceptions.add?(exception) || !try_lock + raise(exception) if !active? || !debugged_exceptions.add?(exception) || !mu_try_lock begin puts exception.backtrace.first.to_s @@ -119,7 +119,7 @@ module Debrew set_trace_func proc { |event, _, _, id, binding, klass| if klass == Object && id == :raise && event == "return" set_trace_func(nil) - synchronize { IRB.start_within(binding) } + mu_synchronize { IRB.start_within(binding) } end } @@ -134,7 +134,7 @@ module Debrew end end ensure - unlock + mu_unlock end end end diff --git a/Library/Homebrew/dev-cmd/update-test.rb b/Library/Homebrew/dev-cmd/update-test.rb index 8bb643b21c..4c92356af5 100644 --- a/Library/Homebrew/dev-cmd/update-test.rb +++ b/Library/Homebrew/dev-cmd/update-test.rb @@ -54,7 +54,7 @@ module Homebrew start_commit = T.let("", T.untyped) end_commit = "HEAD" cd HOMEBREW_REPOSITORY do - start_commit = if (commit = T.let(args.commit, T.nilable(String))) + start_commit = if (commit = args.commit) commit elsif (date = args.before) Utils.popen_read("git", "rev-list", "-n1", "--before=#{date}", "origin/master").chomp diff --git a/Library/Homebrew/ignorable.rb b/Library/Homebrew/ignorable.rb index 5aeeb4dc02..43a7d0af34 100644 --- a/Library/Homebrew/ignorable.rb +++ b/Library/Homebrew/ignorable.rb @@ -1,4 +1,4 @@ -# typed: false +# typed: true # frozen_string_literal: true require "warnings" @@ -30,7 +30,7 @@ module Ignorable rescue Exception => e # rubocop:disable Lint/RescueException unless e.is_a?(ScriptError) e.extend(ExceptionMixin) - e.continuation = continuation + T.cast(e, ExceptionMixin).continuation = continuation end super(e) end @@ -47,7 +47,6 @@ module Ignorable def self.unhook_raise Object.class_eval do - # False positive - https://github.com/rubocop/rubocop/issues/5022 alias_method :raise, :original_raise alias_method :fail, :original_raise undef :original_raise diff --git a/Library/Homebrew/ignorable.rbi b/Library/Homebrew/ignorable.rbi new file mode 100644 index 0000000000..f8b29fefac --- /dev/null +++ b/Library/Homebrew/ignorable.rbi @@ -0,0 +1,8 @@ +# typed: strict + +module Ignorable + include Kernel + # This is a workaround to enable `raise` to be aliased + # @see https://github.com/sorbet/sorbet/issues/2378#issuecomment-569474238 + def self.raise(*); end +end diff --git a/Library/Homebrew/sorbet/rbi/upstream.rbi b/Library/Homebrew/sorbet/rbi/upstream.rbi new file mode 100644 index 0000000000..5d1e457f44 --- /dev/null +++ b/Library/Homebrew/sorbet/rbi/upstream.rbi @@ -0,0 +1,32 @@ +# typed: strict + +# This file contains temporary definitions for fixes that have +# been submitted upstream to https://github.com/sorbet/sorbet. + +module Kernel + # @see https://github.com/sorbet/sorbet/blob/a1e8389/rbi/core/kernel.rbi#L41-L46 + sig do + type_parameters(:U).params( + block: T.proc.params(cont: Continuation).returns(T.type_parameter(:U)) + ).returns(T.type_parameter(:U)) + end + def callcc(&block); end + + # @see https://github.com/sorbet/sorbet/blob/a1e8389/rbi/core/kernel.rbi#L2348-L2363 + sig do + params( + arg0: T.nilable( + T.proc.params( + event: String, + file: String, + line: Integer, + id: T.nilable(Symbol), + binding: T.nilable(Binding), + classname: Object, + ).returns(T.untyped) + ) + ).void + end + sig { params(arg0: NilClass).returns(NilClass) } + def set_trace_func(arg0); end +end