From 8ce8d4e30ab0ad73b7c073a2c95f9f0e60418b02 Mon Sep 17 00:00:00 2001 From: Loren Segal Date: Fri, 8 Aug 2025 08:56:36 -0700 Subject: [PATCH] fix handling of **nil with named block --- lib/yard/parser/ruby/ast_node.rb | 3 ++- spec/handlers/method_handler_spec.rb | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/yard/parser/ruby/ast_node.rb b/lib/yard/parser/ruby/ast_node.rb index ccfa9b6c3..56d73b02b 100644 --- a/lib/yard/parser/ruby/ast_node.rb +++ b/lib/yard/parser/ruby/ast_node.rb @@ -431,7 +431,8 @@ def args_forward # shape is (required, optional, rest, more, keyword, keyword_rest, block) # Ruby 3.1 moves :args_forward from rest to keyword_rest args_index = YARD.ruby31? ? -2 : 2 - self[args_index].type == :args_forward if self[args_index] + node = self[args_index] + node.is_a?(AstNode) && node.type == :args_forward end end diff --git a/spec/handlers/method_handler_spec.rb b/spec/handlers/method_handler_spec.rb index b399570d1..5003ebda7 100644 --- a/spec/handlers/method_handler_spec.rb +++ b/spec/handlers/method_handler_spec.rb @@ -124,6 +124,16 @@ def endless_with_arg(arg = true) = true expect(P('Foo#d_unnamed_splat').parameters).to eq [] end + it "handles **nil with named block" do + YARD.parse_string <<-RUBY + class KwNilBlock + def no_kwargs_with_block(**nil, &block); end + end + RUBY + + expect(P('KwNilBlock#no_kwargs_with_block').parameters).to eq [['&block', nil]] + end if YARD.ruby3? + it "handles overloads" do meth = P('Foo#foo')