Skip to content

Commit d2a8883

Browse files
committed
Merge remote-tracking branch 'origin/main' into fix/issue-1684-struct-data-param-types
2 parents 9483cd3 + 674d0cf commit d2a8883

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- Add compatibility with RDoc 8
55
- Fix TypesExplainer parsing of types following Hash collections (#1688)
66
- Fix HTML generation for RBS constants without source values (#1686)
7+
- Fix method redefinition warnings when loading YARD with Ruby warnings enabled (#1687)
78

89
# [0.9.44] - May 25th, 2026
910

lib/yard/parser/ruby/ruby_parser.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ def on_hash(*args)
379379
# entries from corrupting source ranges of later hash literals and brace blocks.
380380
# Bare hash patterns (key: val without braces) fire no brace scanner events, so
381381
# we only clean up when @map[:rbrace] confirms a closing brace was scanned.
382+
begin; undef on_hshptn; rescue NameError; end
382383
def on_hshptn(*args)
383384
if (@map[:rbrace] ||= []).any?
384385
(@map[:lbrace] ||= []).pop
@@ -443,6 +444,7 @@ def on_array(other)
443444
# on_rbracket scanner events. The corresponding parser events are on_aryptn/on_fndptn
444445
# (not on_aref), so we must clean up the bracket maps to prevent stale entries from
445446
# corrupting source ranges of later array indexing expressions.
447+
begin; undef on_aryptn; rescue NameError; end
446448
def on_aryptn(*args)
447449
(@map[:lbracket] ||= []).pop
448450
(@map[:aref] ||= []).shift
@@ -451,6 +453,7 @@ def on_aryptn(*args)
451453
AstNode.new(:aryptn, args)
452454
end
453455

456+
begin; undef on_fndptn; rescue NameError; end
454457
def on_fndptn(*args)
455458
(@map[:lbracket] ||= []).pop
456459
(@map[:aref] ||= []).shift

spec/parser/ruby/ruby_parser_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# frozen_string_literal: true
2+
require 'open3'
23

34
RSpec.describe YARD::Parser::Ruby::RubyParser do
45
def stmt(stmt)
@@ -13,6 +14,15 @@ def tokenize(stmt)
1314
YARD::Parser::Ruby::RubyParser.new(stmt, nil).parse.tokens
1415
end
1516

17+
it "loads without redefining parser event methods" do
18+
_stdout, stderr, status = Open3.capture3(
19+
RbConfig.ruby, '-w', "-I#{YARD::ROOT}", '-e', "require 'yard'"
20+
)
21+
22+
expect(status).to be_success
23+
expect(stderr).not_to include('method redefined')
24+
end
25+
1626
describe "#parse" do
1727
it "gets comment line numbers" do
1828
s = stmt <<-eof

0 commit comments

Comments
 (0)