Skip to content

Commit 1846a8a

Browse files
committed
Add forward-ref alias regression test for trailing-comment RHS
Codex flagged a ripper-only path where Constant#is_alias_for_path stays nil for +Foo = Bar # comment+: parse_constant_body's on_const branch only fires create_module_alias when the const token is followed by on_nl/EOF, so the trailing comment short-circuits the recording. Pre-PR this was masked by Constant#find_alias_for's lookup-time regex on +value+, which this PR removes. Skip the actual fix -- the ripper parser is on its way out (loads with a deprecation banner, opt-in via RDOC_USE_RIPPER_PARSER=1) and isn't worth a backstop. Keep the test in the shared parser-mixin (RDocParserPrismTestCases) so prism is still guarded against the same shape, and omit it under the legacy ripper variant.
1 parent 3e0ca4e commit 1846a8a

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

test/rdoc/parser/prism_ruby_test.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,6 +1715,24 @@ class Bar; end
17151715
assert_equal 'Foo::Bar', a_const.is_alias_for.full_name
17161716
end
17171717

1718+
def test_constant_alias_with_trailing_comment_resolves_after_complete
1719+
omit if accept_legacy_bug? # ripper parser is deprecated; gap not worth fixing
1720+
util_parser <<~RUBY
1721+
class Foo
1722+
Trailing = Bar # trailing comment
1723+
end
1724+
class Bar; end
1725+
RUBY
1726+
@store.complete(:public)
1727+
foo = @store.classes_hash['Foo']
1728+
trailing = foo.constants.find { |c| c.name == 'Trailing' }
1729+
refute_nil trailing
1730+
refute_nil trailing.is_alias_for,
1731+
'a constant alias whose RHS is followed by a trailing comment ' \
1732+
'should still resolve to its target after Store#complete'
1733+
assert_equal 'Bar', trailing.is_alias_for.full_name
1734+
end
1735+
17181736
def test_repeated_constant_alias
17191737
util_parser <<~RUBY
17201738
# Parsed first

0 commit comments

Comments
 (0)