Go: methods with the same name on different receiver types in one package collapse into one node

Offen
#3,181 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
56/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
go

Rechercherichtung

Start by tracing how Go methods are assigned qualified names during indexing, then inspect the graph query behavior in the minimal repro’s handler/handlers.go. Check how receiver types are represented and compare with the Rust collision fix in #495. Done when both Create methods appear as distinct nodes and route edges resolve to the correct implementation.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

parsing/quality

Summary

In Go, methods with the same name on different receiver types in the same package collapse into a single Method node. The qualified name omits the receiver type (<pkg>.<Method>), so the second definition overwrites the first. Downstream edges (HANDLES, CALLS, trace_path) then point to the wrong implementation.

Minimal repro (v0.12.1, darwin-arm64)

go.mod

module example.com/repro

go 1.22

handler/handlers.go

package handler

type ReminderHandler struct{}

func (h *ReminderHandler) Create() string { return "reminder" }

type CampaignHandler struct{}

func (h *CampaignHandler) Create() string { return "campaign" }
codebase-memory-mcp cli index_repository '{"repo_path":"<repro>","name":"repro","mode":"full"}'
codebase-memory-mcp cli query_graph '{"project":"repro","query":"MATCH (m:Method) RETURN m.name, m.qualified_name, m.start_line"}'

Actual: one row — Create | repro.handler.Create | 9
Expected: two rows, e.g. repro.handler.ReminderHandler.Create (line 5) and repro.handler.CampaignHandler.Create (line 9).

Impact on a real codebase

This pattern is idiomatic Go (several handlers/DAOs in one package, each with Create/List/Get). Counting (package dir, method name) pairs with more than one receiver across three Gin services:

service methods collapsed
A 910 95 (10.4%)
B 174 29 (16.7%)
C 1618 372 (23.0%)

Example consequence: the HANDLES edge for /api/v1/reminders/create resolves to CampaignHandler.Create, so "which function handles this route?" returns the wrong answer.

Suggestion

Include the receiver type name in Go method qualified names (<pkg>.<Recv>.<Method>), similar to how the Rust cfg collision was addressed in #495. Related: #1911 (Go build-tag twin files colliding on one QN), #2061 (Swift overloads collapsing).

Vorherrschende Sprache
C
Sterne
45.8k
Forks
3.8k
Ø Merge
2 T. 18 Std.
Gemergte PRs (30 T.)
108

Entwicklungsumgebung

Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus DeusData/codebase-memory-mcp

Alle Issues in DeusData/codebase-memory-mcp

Ähnliche Issues

Weitere Issues zu C

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.