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

Đang mở
#3,181 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
56/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
go

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
C
Star
45.8k
Fork
3.8k
Merge trung bình
2 ngày 18 giờ
Pull request đã merge (30 ngày)
108

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của DeusData/codebase-memory-mcp

Tất cả issue của DeusData/codebase-memory-mcp

Issue tương tự

Thêm issue về C

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.