Skip to content

[Bug]: Go: when two packages each declare a type with the same name, every s.method() call on those types is dropped (since 0.9.102) #5242

Open

Description

@Modeux

Pre-flight checks

  • I have checked the Troubleshooting section in the README

What happened?

In Go, if two packages each declare a type with the same name (alpha.Service
and beta.Service), every calls edge from a method of those types to another
method on the same receiver (s.helper()) goes away. Both types lose their
edges, and types with a unique name in the same build keep theirs.

The receiver's type is declared in the same file as the call, so there is only
one candidate in scope. It looks as if the receiver type is looked up by its bare
name across the whole corpus, finds two candidates, and is then treated as
ambiguous. I have not read the resolver code.

This started in 0.9.102, the release that landed #4966 ("resolve same-file member
calls through receiver types"). 0.9.101 emits the edges and binds each one to
the method in its own package. 0.9.111 still drops them.

A type name shared across packages is the ordinary layout for a Go service: one
package per domain, each with its own Service, Handler and Repository. On a
monorepo with about 1,050 non-test Go files laid out that way, going from 0.9.101
to 0.9.111 took calls edges from 16,685 to 14,096, and same-file calls edges
from 8,077 to 5,691. Methods such as an HTTP client's doJSON went from 13
callers to 0, so graphify affected --relation calls no longer reaches helpers
from the service methods that call them.

Expected: Run -> helper for every type in all five cases below.

Steps to reproduce

# uv run --no-project --with graphifyy==0.9.111 python repro.py
import importlib.metadata as md
import tempfile
from pathlib import Path

from graphify.extract import extract

GO = """package {pkg}

type {typ} struct{{}}

func (s *{typ}) helper() int {{ return 1 }}

func (s *{typ}) Run() int {{ return s.helper() }}
"""


def build(pkgs):
    """pkgs: (package, file name, type name) triples. Returns the raw extraction."""
    with tempfile.TemporaryDirectory() as t, tempfile.TemporaryDirectory() as cache:
        root = Path(t) / "app"
        root.mkdir()
        (root / "go.mod").write_text("module example.com/app\n\ngo 1.22\n")
        for pkg, fname, typ in pkgs:
            (root / pkg).mkdir(exist_ok=True)
            (root / pkg / fname).write_text(GO.format(pkg=pkg, typ=typ))
        return extract(sorted(root.rglob("*.go")), root=root, cache_root=Path(cache))


def case(label, pkgs):
    r = build(pkgs)
    calls = sorted(
        f"{e['source']} -> {e['target']} [{e.get('confidence')}]"
        for e in r["edges"] if e.get("relation") == "calls"
    )
    print(f"{label:<58} {calls}")


if __name__ == "__main__":
    print("graphifyy", md.version("graphifyy"))
    case("1. alpha.Service only", [("alpha", "impl.go", "Service")])
    case("2. alpha.AlphaService + beta.BetaService", [("alpha", "impl.go", "AlphaService"), ("beta", "impl.go", "BetaService")])
    case("3. alpha.Service + beta.Service (impl.go in both)", [("alpha", "impl.go", "Service"), ("beta", "impl.go", "Service")])
    case("4. alpha.Service + beta.Service (a.go / b.go)", [("alpha", "a.go", "Service"), ("beta", "b.go", "Service")])
    case("5. alpha.Service + beta.Service + gamma.Other", [("alpha", "a.go", "Service"), ("beta", "b.go", "Service"), ("gamma", "c.go", "Other")])

Error output or graph output

graphifyy 0.9.111
1. alpha.Service only                                      ['alpha_service_run -> alpha_service_helper [INFERRED]']
2. alpha.AlphaService + beta.BetaService                   ['alpha_alphaservice_run -> alpha_alphaservice_helper [INFERRED]', 'beta_betaservice_run -> beta_betaservice_helper [
INFERRED]']
3. alpha.Service + beta.Service (impl.go in both)          []
4. alpha.Service + beta.Service (a.go / b.go)              []
5. alpha.Service + beta.Service + gamma.Other              ['gamma_other_run -> gamma_other_helper [INFERRED]']


0.9.102 prints the same five lines. 0.9.101 keeps every edge:


graphifyy 0.9.101
1. alpha.Service only                                      ['alpha_service_run -> alpha_service_helper [EXTRACTED]']
2. alpha.AlphaService + beta.BetaService                   ['alpha_alphaservice_run -> alpha_alphaservice_helper [EXTRACTED]', 'beta_betaservice_run -> beta_betaservice_helper
[EXTRACTED]']
3. alpha.Service + beta.Service (impl.go in both)          ['alpha_service_run -> alpha_service_helper [EXTRACTED]', 'beta_service_run -> beta_service_helper [EXTRACTED]']
4. alpha.Service + beta.Service (a.go / b.go)              ['alpha_service_run -> alpha_service_helper [EXTRACTED]', 'beta_service_run -> beta_service_helper [EXTRACTED]']
5. alpha.Service + beta.Service + gamma.Other              ['alpha_service_run -> alpha_service_helper [EXTRACTED]', 'beta_service_run -> beta_service_helper [EXTRACTED]', 'gam
ma_other_run -> gamma_other_helper [EXTRACTED]']


Cases 3 and 4 give the same result, so the file name plays no part. In case 5 the
uniquely named `gamma.Other` keeps its edge while both `Service` types lose
theirs. The nodes and `method` edges are identical between 0.9.101 and 0.9.111 in
every case (`alpha_service`, `alpha_service_run`, `alpha_service_helper`, and the
`beta_` twins); only the `calls` edges differ.

This is not #5209. No `_test.go` file is involved, and 0.9.110's fix for that
issue leaves this output unchanged.

Graphify version

0.9.111 (also 0.9.102; last good version is 0.9.101)

Operating System

macOS

Python Version

3.13

Installation Method

uv tool install (recommended)

Additional Environment Details

Each version ran in a throwaway environment (uv run --no-project --with graphifyy==<version>), calling graphify.extract.extract on a fresh temporary
directory with a fresh cache_root, so no cache or existing graph is involved.
No provider keys are set; the run is AST-only.

Additional context

No response

Activity

  1. github-actions commented on Nov 16, 2026

    @github-actions

    Thanks for opening this issue, @Modeux. A maintainer will take a look soon.

    If you would like to discuss it in real time, come say hi on our Discord server. For longer-form questions and ideas there is also GitHub Discussions.

    To help us triage, please make sure the report includes what you expected, what actually happened, and the steps (and a small sample) to reproduce it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions