Merge pull request #15114 from dduugg/ignorable-type

Enable typing in Ignorable
This commit is contained in:
Mike McQuaid 2023-04-03 08:37:34 +01:00 committed by GitHub
commit 830ec2847b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 49 additions and 10 deletions

View File

@ -1,4 +1,4 @@
# typed: false # typed: true
# frozen_string_literal: true # frozen_string_literal: true
require "mutex_m" require "mutex_m"
@ -47,7 +47,7 @@ module Debrew
menu = new menu = new
yield menu yield menu
choice = nil choice = T.let(nil, T.nilable(Entry))
while choice.nil? while choice.nil?
menu.entries.each_with_index { |e, i| puts "#{i + 1}. #{e.name}" } menu.entries.each_with_index { |e, i| puts "#{i + 1}. #{e.name}" }
print menu.prompt unless menu.prompt.nil? print menu.prompt unless menu.prompt.nil?
@ -90,7 +90,7 @@ module Debrew
yield yield
rescue SystemExit rescue SystemExit
raise 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 e.ignore if debug(e) == :ignore # execution jumps back to where the exception was thrown
ensure ensure
Ignorable.unhook_raise Ignorable.unhook_raise
@ -99,7 +99,7 @@ module Debrew
end end
def self.debug(exception) 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 begin
puts exception.backtrace.first.to_s puts exception.backtrace.first.to_s
@ -119,7 +119,7 @@ module Debrew
set_trace_func proc { |event, _, _, id, binding, klass| set_trace_func proc { |event, _, _, id, binding, klass|
if klass == Object && id == :raise && event == "return" if klass == Object && id == :raise && event == "return"
set_trace_func(nil) set_trace_func(nil)
synchronize { IRB.start_within(binding) } mu_synchronize { IRB.start_within(binding) }
end end
} }
@ -134,7 +134,7 @@ module Debrew
end end
end end
ensure ensure
unlock mu_unlock
end end
end end
end end

View File

@ -54,7 +54,7 @@ module Homebrew
start_commit = T.let("", T.untyped) start_commit = T.let("", T.untyped)
end_commit = "HEAD" end_commit = "HEAD"
cd HOMEBREW_REPOSITORY do cd HOMEBREW_REPOSITORY do
start_commit = if (commit = T.let(args.commit, T.nilable(String))) start_commit = if (commit = args.commit)
commit commit
elsif (date = args.before) elsif (date = args.before)
Utils.popen_read("git", "rev-list", "-n1", "--before=#{date}", "origin/master").chomp Utils.popen_read("git", "rev-list", "-n1", "--before=#{date}", "origin/master").chomp

View File

@ -1,4 +1,4 @@
# typed: false # typed: true
# frozen_string_literal: true # frozen_string_literal: true
require "warnings" require "warnings"
@ -30,7 +30,7 @@ module Ignorable
rescue Exception => e # rubocop:disable Lint/RescueException rescue Exception => e # rubocop:disable Lint/RescueException
unless e.is_a?(ScriptError) unless e.is_a?(ScriptError)
e.extend(ExceptionMixin) e.extend(ExceptionMixin)
e.continuation = continuation T.cast(e, ExceptionMixin).continuation = continuation
end end
super(e) super(e)
end end
@ -47,7 +47,6 @@ module Ignorable
def self.unhook_raise def self.unhook_raise
Object.class_eval do Object.class_eval do
# False positive - https://github.com/rubocop/rubocop/issues/5022
alias_method :raise, :original_raise alias_method :raise, :original_raise
alias_method :fail, :original_raise alias_method :fail, :original_raise
undef :original_raise undef :original_raise

View File

@ -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

View File

@ -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