Enable typing in Ignorable

This commit is contained in:
Douglas Eichelberger 2023-03-31 08:34:33 -07:00
parent 6188f230f4
commit d1dfce578c
4 changed files with 48 additions and 9 deletions

View File

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

View File

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

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