Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
fix(go): a chained call on an external return type is not a bare-name call (#2766)
Raghav Chamadiyad4ecf669c303
diff --git a/packages/core/src/repowise/core/ingestion/call_resolver.py b/packages/core/src/repowise/core/ingestion/call_resolver.pyindex a4c41d379..1766f830c 100644--- a/packages/core/src/repowise/core/ingestion/call_resolver.py+++ b/packages/core/src/repowise/core/ingestion/call_resolver.py@@ -119,11 +119,11 @@ def _is_property_accessor(sym: Any) -> bool:# Languages admitted to the full return-type chain lane; each is admitted# explicitly, once measured.-PRODUCTION_RETURN_TYPE_CHAIN_LANGUAGES: frozenset[str] = frozenset({"cpp"})+PRODUCTION_RETURN_TYPE_CHAIN_LANGUAGES: frozenset[str] = frozenset({"cpp", "go"})# Chain lanes that need a file or import/re-export identity for the head type:# a repository-global simple type name is not a language binding.-_BOUND_CHAIN_LANGUAGES = frozenset({"java", "csharp", "typescript"})+_BOUND_CHAIN_LANGUAGES = frozenset({"java", "csharp", "typescript", "go"})def _overload_return_types(@@ -813,6 +813,11 @@ class CallResolver(LanguageStrategiesMixin, ReceiverTypingMixin):# methods, so the repository cannot declare its method: the# bare-name answer is disproved, not merely unevidenced.return from_table+ if language == "go":+ # A go method is declared in its receiver type's package and go has+ # no extension methods, so a head type with no repository method,+ # declared here or not, leaves nothing for the bare name to find.+ return Trueif language in ("csharp", "typescript"):return Falsereturn type_name in self._known_type_namesdiff --git a/packages/core/src/repowise/core/ingestion/parser.py b/packages/core/src/repowise/core/ingestion/parser.pyindex bcc8ffca1..418804f07 100644--- a/packages/core/src/repowise/core/ingestion/parser.py+++ b/packages/core/src/repowise/core/ingestion/parser.py@@ -180,6 +180,7 @@ def _call_receiver_from_node(node: Node, src: str) -> CallReceiver | None:function.child_by_field_name("expression")or function.child_by_field_name("object")or function.child_by_field_name("argument")+ or function.child_by_field_name("operand"))if target is None:diff --git a/packages/core/src/repowise/core/ingestion/queries/go.scm b/packages/core/src/repowise/core/ingestion/queries/go.scmindex 115fefa6c..dbd695b2a 100644--- a/packages/core/src/repowise/core/ingestion/queries/go.scm+++ b/packages/core/src/repowise/core/ingestion/queries/go.scm@@ -85,7 +85,7 @@; Chained call: obj.Method1().Method2(args)(call_expressionfunction: (selector_expression- operand: (call_expression)+ operand: (call_expression) @call.receiver_callfield: (field_identifier) @call.target)arguments: (argument_list) @call.argumentsdiff --git a/packages/core/src/repowise/core/ingestion/return_types.py b/packages/core/src/repowise/core/ingestion/return_types.pyindex 181b982ed..8b3ec390a 100644--- a/packages/core/src/repowise/core/ingestion/return_types.py+++ b/packages/core/src/repowise/core/ingestion/return_types.py@@ -61,6 +61,8 @@ def normalize_return_type(raw: str, language: str) -> str | None:value = value.removeprefix("global::").rstrip("?").strip()if language == "java":value = value.rstrip("?").strip()+ if language == "go":+ value = value.lstrip("*").strip()if language == "cpp":value = _CPP_PREFIX.sub("", value)while _CPP_SUFFIX.search(value):diff --git a/tests/unit/ingestion/test_return_type_chain_resolution.py b/tests/unit/ingestion/test_return_type_chain_resolution.pyindex d6f4b8869..6884494bd 100644--- a/tests/unit/ingestion/test_return_type_chain_resolution.py+++ b/tests/unit/ingestion/test_return_type_chain_resolution.py@@ -214,8 +214,8 @@ def test_unbound_global_return_type_preserves_legacy_fallback(assert after == before-def test_only_audited_cpp_lane_is_enabled_by_default() -> None:- assert frozenset({"cpp"}) == PRODUCTION_RETURN_TYPE_CHAIN_LANGUAGES+def test_only_audited_lanes_are_enabled_by_default() -> None:+ assert frozenset({"cpp", "go"}) == PRODUCTION_RETURN_TYPE_CHAIN_LANGUAGESdef test_module_level_chain_keeps_structural_receiver(tmp_path: Path) -> None:@@ -352,3 +352,112 @@ def test_java_external_chain_head_is_exempt_when_the_repo_declares_the_name()assert len(resolved) == 1assert resolved[0].callee_id.endswith("::Duration::toNanos")+++def _go_packages(tmp_path: Path, files: dict[str, str]) -> dict[str, ParsedFile]:+ parsed: dict[str, ParsedFile] = {}+ for path, source in files.items():+ (tmp_path / path).parent.mkdir(parents=True, exist_ok=True)+ parsed.update(_parse(tmp_path, path, "go", source))+ # Stands in for the import-resolution phase, which unit tests do not run.+ for imp in parsed["cmd/run.go"].imports:+ imp.resolved_file = "logging/log.go"+ return parsed+++def _go_chain(parsed: dict[str, ParsedFile], outer: str):+ return next(+ c for c in parsed["cmd/run.go"].calls if c.target_name == outer and c.receiver_call+ )+++_GO_CALLER = (+ 'package cmd\n\nimport "example.com/m/logging"\n\n'+ "func run(e error) {\n\tlogging.Error().Err(e)\n}\n"+)+++def test_go_chain_on_an_external_return_type_refuses_the_bare_name(tmp_path: Path) -> None:+ """`logging.Error().Err(e)` calls zerolog's `Err`, not the package's own `Err`.++ The imported package declares an unrelated `Err` function, which the+ import-scoped bare-name tier used to bind the chained call to.+ """+ parsed = _go_packages(+ tmp_path,+ {+ "logging/log.go": (+ 'package logging\n\nimport "github.com/rs/zerolog"\n\n'+ "func Error() *zerolog.Event { return nil }\n\n"+ "func Err(err error) *zerolog.Event { return nil }\n"+ ),+ "cmd/run.go": _GO_CALLER,+ },+ )+ call = _go_chain(parsed, "Err")+ assert call.receiver_call.receiver_name == "logging"+ imports = {"cmd/run.go": {"logging/log.go"}}++ before = CallResolver(+ parsed, imports, repo_path=str(tmp_path), return_type_chain_languages=frozenset()+ ).resolve_file("cmd/run.go", [call])+ after = CallResolver(parsed, imports, repo_path=str(tmp_path)).resolve_file(+ "cmd/run.go", [call]+ )++ assert [edge.callee_id for edge in before] == ["logging/log.go::Err"]+ assert after == []+++def test_go_chain_on_a_repository_return_type_binds_its_method(tmp_path: Path) -> None:+ """The same shape over a type the repository declares resolves to that type's method."""+ parsed = _go_packages(+ tmp_path,+ {+ "logging/log.go": (+ "package logging\n\ntype Event struct{}\n\n"+ "func (e *Event) Err(err error) *Event { return e }\n\n"+ "func Error() *Event { return &Event{} }\n\n"+ "func Err(err error) *Event { return nil }\n"+ ),+ "cmd/run.go": _GO_CALLER,+ },+ )+ call = _go_chain(parsed, "Err")++ resolved = CallResolver(+ parsed, {"cmd/run.go": {"logging/log.go"}}, repo_path=str(tmp_path)+ ).resolve_file("cmd/run.go", [call])++ assert len(resolved) == 1+ assert resolved[0].callee_id == "logging/log.go::Event::Err"+ assert resolved[0].origin.startswith("return_type_")+++def test_go_external_return_type_does_not_bind_a_same_named_repo_type(tmp_path: Path) -> None:+ """`*zerolog.Event` is not the repository's own `Event` in an unrelated package.++ Go types are package-scoped, so a repository-wide match on the bare type+ name is a coincidence rather than a binding, the same as java's.+ """+ parsed = _go_packages(+ tmp_path,+ {+ "logging/log.go": (+ 'package logging\n\nimport "github.com/rs/zerolog"\n\n'+ "func Error() *zerolog.Event { return nil }\n"+ ),+ "audit/event.go": (+ "package audit\n\ntype Event struct{}\n\n"+ "func (e *Event) Err(err error) *Event { return e }\n"+ ),+ "cmd/run.go": _GO_CALLER,+ },+ )+ call = _go_chain(parsed, "Err")++ resolved = CallResolver(+ parsed, {"cmd/run.go": {"logging/log.go"}}, repo_path=str(tmp_path)+ ).resolve_file("cmd/run.go", [call])++ assert resolved == []diff --git a/tests/unit/ingestion/test_return_types.py b/tests/unit/ingestion/test_return_types.pyindex 655ecb035..2ab05ddb0 100644--- a/tests/unit/ingestion/test_return_types.py+++ b/tests/unit/ingestion/test_return_types.py@@ -34,6 +34,8 @@ def test_signature_parameter_count(signature: str, expected: int | None) -> None("const seastar::future<Result>&", "cpp", "future"),("global::System.Threading.Tasks.Task<Result>?", "csharp", "Task"),("Promise<Result> | null", "typescript", "Promise"),+ ("*Event", "go", "Event"),+ ("*zerolog.Event", "go", "Event"),],)def test_normalize_return_type_keeps_the_declared_wrapper(