fix: guard Ruby namespace rebinding

(cherry picked from commit 1a7262e2a8)
This commit is contained in:
oleksii-tumanov authored and safishamsi committed 2026-09-15 18:03:49 +01:00
1 parent 436a735f7f
commit 7e857e020b
3 files changed
+144 -13

No files matched your search

+79
View File
@@ -937,6 +937,55 @@ def test_external_owner_mutator_through_constant_alias_stays_inferred(
assert _only_call(graph)["confidence"] == "INFERRED"
def test_qualified_external_owner_through_namespace_alias_stays_inferred(
tmp_path: Path,
) -> None:
_write(tmp_path, "base.rb", "class Base\n def self.helper; :base; end\nend\n")
_write(
tmp_path,
"child.rb",
"module Namespace\n class Child < Base\n"
" def self.call\n helper()\n end\n end\nend\n",
)
_write(
tmp_path,
"override.rb",
"AliasNS = Namespace\n"
"AliasNS::Child.define_singleton_method(:helper) { :child }\n",
)
graph = extract(sorted(tmp_path.glob("*.rb")), cache_root=tmp_path, parallel=False)
assert _only_call(graph)["confidence"] == "INFERRED"
def test_qualified_superclass_under_rebound_namespace_stays_inferred(
tmp_path: Path,
) -> None:
_write(
tmp_path,
"base.rb",
"module Namespace\n class Base\n"
" def self.helper; :wrong; end\n end\nend\n",
)
_write(
tmp_path,
"other.rb",
"module Other\n class Base\n class << self\n"
" attr_reader :helper\n end\n end\nend\n",
)
_write(
tmp_path,
"child.rb",
"Namespace = Other\nclass Child < Namespace::Base\n"
" def self.call\n helper()\n end\nend\n",
)
graph = extract(sorted(tmp_path.glob("*.rb")), cache_root=tmp_path, parallel=False)
assert _only_call(graph)["confidence"] == "INFERRED"
def test_inherited_call_stays_inferred_for_compact_reopening(
tmp_path: Path,
) -> None:
@@ -980,6 +1029,36 @@ def test_absolute_class_declaration_inside_namespace_stays_inferred(
assert _only_call(graph)["confidence"] == "INFERRED"
def test_qualified_superclass_stops_at_nearer_lexical_prefix(
tmp_path: Path,
) -> None:
_write(
tmp_path,
"base.rb",
"module Outer\n module Services\n class Base\n"
" def self.helper; :wrong; end\n end\n end\nend\n",
)
_write(
tmp_path,
"provider.rb",
"class Provider\n class Base\n class << self\n"
" attr_reader :helper\n end\n end\nend\n",
)
_write(
tmp_path,
"child.rb",
"module Outer\n module Inner\n"
" class Services < ::Provider; end\n"
" class Child < Services::Base\n"
" def self.call\n helper()\n end\n end\n"
" end\nend\n",
)
graph = extract(sorted(tmp_path.glob("*.rb")), cache_root=tmp_path, parallel=False)
assert _only_call(graph)["confidence"] == "INFERRED"
def test_inherited_call_stops_at_ambiguous_nearer_method(tmp_path: Path) -> None:
_write(tmp_path, "grand.rb", "class Grand\n def helper; :grand; end\nend\n")
_write(