Skip to content

Commit fe6b07d

Browse files
p-ddsignclaude
andcommitted
SymDB: skip subclass+autoload test on Ruby < 2.7
The "subclass with constant of same name as ancestor pending autoload" test verifies that resolves_to_same_module? distinguishes a real subclass binding from an ancestor's pending autoload. That distinction requires Module#autoload?(name, false) to query autoloads registered directly on a namespace without checking ancestors. The `inherit` parameter was added in Ruby 2.7 (Ruby 2.7.0 NEWS). On Ruby 2.5/2.6 the implementation falls back to Module#autoload?(name) which checks ancestors — so a subclass binding that collides with an ancestor's pending autoload is conservatively treated as stale and dropped. That fallback is documented in resolves_to_same_module?'s YARD comment and is unavoidable without the 2.7+ API. Skip the test on Ruby < 2.7 to align verification with the platform that supports the asserted behavior. The conservative-fallback behavior on 2.5/2.6 is already exercised by every leaked-class case in collect_extractable_modules. Co-Authored-By: Claude <[email protected]>
1 parent 8f6a5d7 commit fe6b07d

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

spec/datadog/symbol_database/extractor_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2337,6 +2337,17 @@ def host_method; end
23372337
# The fix relies on the order of operations: const_defined?(sym, false)
23382338
# detects the direct subclass binding first, and const_get(sym, false)
23392339
# returns it without triggering the ancestor's autoload.
2340+
#
2341+
# Requires Module#autoload?(name, inherit) — the `inherit` parameter was
2342+
# added in Ruby 2.7 (Ruby 2.7.0 NEWS). On Ruby 2.5/2.6 the fallback in
2343+
# resolves_to_same_module? uses autoload?(name) which checks ancestors,
2344+
# so a subclass binding that collides with an ancestor's pending
2345+
# autoload is conservatively treated as stale and dropped. That is the
2346+
# documented fallback behavior and is unavoidable without the 2.7+ API.
2347+
before(:all) do
2348+
skip 'requires Module#autoload?(name, inherit) — Ruby 2.7+' if RUBY_VERSION < '2.7'
2349+
end
2350+
23402351
before do
23412352
@parent_file = create_test_file('autoload_parent.rb', <<~RUBY)
23422353
class ExtractAllAutoloadParent

0 commit comments

Comments
 (0)