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

未关闭
#3,181 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
56/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
go

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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).

主要语言
C
星标
45.8k
派生
3.8k
平均合并
2 天 18 小时
30 天内合并 PR
108

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

DeusData/codebase-memory-mcp 的其他 Issue

查看 DeusData/codebase-memory-mcp 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。