Skip to content

Commit

Permalink
Fix Ruby 3.4dev unused block warnings
Browse files Browse the repository at this point in the history
Ref: https://bugs.ruby-lang.org/issues/15554

The warning is still being fined tuned, so this change is mostly
to identify the false positive and the actual issues.

Overall, among a few dozens warnings, one was a true positive,
all others were duck typing related false positives, or caused
by `...` delegation.

The one true positive is very valuable though.
  • Loading branch information
byroot committed Apr 17, 2024
1 parent 64fadc6 commit 640c7c7
Show file tree
Hide file tree
Showing 18 changed files with 29 additions and 22 deletions.
2 changes: 1 addition & 1 deletion actionmailer/lib/action_mailer/message_delivery.rb
Expand Up @@ -28,7 +28,7 @@ def initialize(mailer_class, action, *args) # :nodoc:
ruby2_keywords(:initialize)

# Method calls are delegated to the Mail::Message that's ready to deliver.
def __getobj__ # :nodoc:
def __getobj__(&_) # :nodoc:
@mail_message ||= processed_mailer.message
end

Expand Down
10 changes: 8 additions & 2 deletions actionview/lib/action_view/template.rb
Expand Up @@ -438,9 +438,13 @@ def compiled_source

method_arguments =
if set_strict_locals
"output_buffer, #{set_strict_locals}"
if set_strict_locals.include?("&")
"output_buffer, #{set_strict_locals}"
else
"output_buffer, #{set_strict_locals}, &_"
end
else
"local_assigns, output_buffer"
"local_assigns, output_buffer, &_"
end

# Make sure that the resulting String to be eval'd is in the
Expand Down Expand Up @@ -505,6 +509,8 @@ def compile(mod)
![:keyreq, :key, :keyrest, :nokey].include?(parameter[0])
end

non_kwarg_parameters.pop if non_kwarg_parameters.last == %i(block _)

unless non_kwarg_parameters.empty?
mod.undef_method(method_name)

Expand Down
2 changes: 1 addition & 1 deletion actionview/lib/action_view/template/raw_file.rb
Expand Up @@ -17,7 +17,7 @@ def identifier
@filename
end

def render(*args)
def render(*args, &_)
::File.read(@filename)
end
end
Expand Down
2 changes: 1 addition & 1 deletion actionview/lib/action_view/template/renderable.rb
Expand Up @@ -12,7 +12,7 @@ def identifier
@renderable.class.name
end

def render(context, *args)
def render(context, *args, &_)
@renderable.render_in(context)
rescue NoMethodError
if !@renderable.respond_to?(:render_in)
Expand Down
2 changes: 1 addition & 1 deletion actionview/lib/action_view/template/text.rb
Expand Up @@ -20,7 +20,7 @@ def to_str
@string
end

def render(*args)
def render(*args, &_)
to_str
end

Expand Down
2 changes: 1 addition & 1 deletion actionview/test/template/template_test.rb
Expand Up @@ -62,7 +62,7 @@ def new_template(body = "<%= hello %>", details = {})
ActionView::Template.new(body.dup, "hello template", details.delete(:handler) || ERBHandler, virtual_path: "hello", **details)
end

def render(implicit_locals: [], **locals)
def render(implicit_locals: [], **locals, &_)
@template.render(@context, locals, implicit_locals: implicit_locals)
end

Expand Down
2 changes: 1 addition & 1 deletion activejob/lib/active_job/enqueuing.rb
Expand Up @@ -75,7 +75,7 @@ def perform_later(...)
end

private
def job_or_instantiate(*args) # :doc:
def job_or_instantiate(*args, &_) # :doc:
args.first.is_a?(self) ? args.first : new(*args)
end
ruby2_keywords(:job_or_instantiate)
Expand Down
2 changes: 1 addition & 1 deletion activemodel/lib/active_model/attribute.rb
Expand Up @@ -38,7 +38,7 @@ def initialize(name, value_before_type_cast, type, original_attribute = nil, val
@value = value unless value.nil?
end

def value
def value(&_)
# `defined?` is cheaper than `||=` when we get back falsy values
@value = type_cast(value_before_type_cast) unless defined?(@value)
@value
Expand Down
2 changes: 1 addition & 1 deletion activemodel/lib/active_model/type/value.rb
Expand Up @@ -25,7 +25,7 @@ def initialize(precision: nil, limit: nil, scale: nil)
# by the database. For example a boolean type can return +true+ if the
# value parameter is a Ruby boolean, but may return +false+ if the value
# parameter is some other object.
def serializable?(value)
def serializable?(value, &_)
true
end

Expand Down
Expand Up @@ -106,7 +106,7 @@ def initialize(reflection, aliased_table)
@aliased_table = aliased_table
end

def all_includes; nil; end
def all_includes(&_); nil; end
end

def get_chain(reflection, association, tracker)
Expand Down
Expand Up @@ -118,7 +118,7 @@ def invalidate!; end
def materialized?; false; end
def before_commit; yield; end
def after_commit; yield; end
def after_rollback; end # noop
def after_rollback(&_); end # noop
end

class Transaction < ActiveRecord::Transaction # :nodoc:
Expand Down
4 changes: 2 additions & 2 deletions activerecord/lib/active_record/statement_cache.rb
Expand Up @@ -74,13 +74,13 @@ def <<(str)
self
end

def add_bind(obj)
def add_bind(obj, &_)
@binds << obj
@parts << Substitute.new
self
end

def add_binds(binds, proc_for_binds = nil)
def add_binds(binds, proc_for_binds = nil, &_)
@binds.concat proc_for_binds ? binds.map(&proc_for_binds) : binds
binds.size.times do |i|
@parts << ", " unless i == 0
Expand Down
4 changes: 2 additions & 2 deletions activerecord/lib/arel/collectors/bind.rb
Expand Up @@ -13,12 +13,12 @@ def <<(str)
self
end

def add_bind(bind)
def add_bind(bind, &_)
@binds << bind
self
end

def add_binds(binds, proc_for_binds = nil)
def add_binds(binds, proc_for_binds = nil, &_)
@binds.concat proc_for_binds ? binds.map(&proc_for_binds) : binds
self
end
Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/arel/collectors/substitute_binds.rb
Expand Up @@ -15,7 +15,7 @@ def <<(str)
self
end

def add_bind(bind)
def add_bind(bind, &_)
bind = bind.value_for_database if bind.respond_to?(:value_for_database)
self << quoter.quote(bind)
end
Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/arel/nodes/node.rb
Expand Up @@ -152,7 +152,7 @@ def to_sql(engine = Table.engine)
end
end

def fetch_attribute
def fetch_attribute(&_)
end

def equality?; false; end
Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/arel/nodes/sql_literal.rb
Expand Up @@ -19,7 +19,7 @@ def encode_with(coder)
coder.scalar = self.to_s
end

def fetch_attribute
def fetch_attribute(&_)
end

def +(other)
Expand Down
4 changes: 2 additions & 2 deletions activesupport/lib/active_support/core_ext/object/try.rb
Expand Up @@ -145,14 +145,14 @@ class NilClass
#
# With +try+
# @person.try(:children).try(:first).try(:name)
def try(*)
def try(*, &_)
nil
end

# Calling +try!+ on +nil+ always returns +nil+.
#
# nil.try!(:name) # => nil
def try!(*)
def try!(*, &_)
nil
end
end
3 changes: 2 additions & 1 deletion activesupport/test/time_travel_test.rb
Expand Up @@ -332,11 +332,12 @@ def test_time_helper_with_usec_true

def test_time_helper_freeze_time_with_usec_true
# repeatedly test in case Time.now happened to actually be 0 usec
assert_predicate 9.times, :any? do
checks = 9.times.map do
freeze_time(with_usec: true) do
Time.now.usec != 0
end
end
assert_predicate checks, :any?
end

def test_time_helper_travel_with_subsequent_block
Expand Down

0 comments on commit 640c7c7

Please sign in to comment.