feat: Go extractor records no read of a composite-literal element value

Đang mở
#356 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ó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
68/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
Lĩnh vực
tooling

Hướng nghiên cứu

Start in internal/indexer/goextract/goextract.go: the composite_literal case of captureExprRead (~1184) delegates to captureCompositeElements (~1249) and captureElementWrites (~1277), which only record field writes. Add a read for each element value (bare identifier, selector, call, nested literal) across slice, struct, map-key and map-value positions, and fix the stale comment at 956-962. Check behavior with the p.go repro and internal/indexer/bindings_test.go, then run task golden:regen and task corpora:measure and update the hugo goldens, corpora/observations.json, docs/CORPUS-MEASUREMENT.md, matrix.go:101 and docs/LANGUAGE-CAPABILITY-MATRIX.md:126.

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

Mô tả

area:indexer enhancement needs-triage
What exists today?

internal/indexer/goextract/goextract.go records no read for a value that a composite literal element holds.

How does it behave now?

Repro in a file p.go:

package p

type T struct{ F int }

func f(v, a, b int) {
	_ = T{F: v}
	_ = []int{a, b}
	_ = map[int]int{a: b}
}

f gets a write reference to F and an instantiates reference to T. f gets no read reference to v, a or b. The map key a gets no read either.

The cause is in the composite-literal path:

  • collectReferencesAndInstantiates sends a composite_literal to captureExprRead and stops (goextract.go:986).
  • The composite_literal case of captureExprRead (goextract.go:1184-1188) calls recordInstantiate and captureCompositeElements. It never reads an element value.
  • captureCompositeElements (goextract.go:1249-1272) records only an AccessWrite member reference for a keyed element.
  • captureElementWrites (goextract.go:1277-1299) acts only on literal_value, composite_literal and unary_expression. A bare identifier, selector or call records nothing.
  • captureExprRead has no literal_element case.

The block comment at goextract.go:956-962 says element values are read positions. The code does not do that, so the comment is stale.

The gap is recorded as a known limit in internal/indexer/capability/matrix.go:101 and docs/LANGUAGE-CAPABILITY-MATRIX.md:126. #342 left it open because recording the reads changes explore ranking and a hugo golden.

Effect: codegraph node and callers-style read queries miss these reads. The planned Accessed by ← line in #335 misses them too.

How should it behave?

A composite-literal element value records a read reference from the enclosing function. This covers bare identifiers, selectors, calls and nested literals, in slice elements, struct fields, map keys and map values. A keyed struct element still records its write to the field.

For the repro, f gets read references to v, a and b. It keeps the write to F and the instantiates reference to T.

The same change must fix the stale comment at goextract.go:956-962.

The fix changes these artifacts, and the PR must update each one:

  • Hugo goldens under testdata/golden/corpus/hugo/ (go-explore*.json, probably go-node*.json), checked by TestGoldensMatchLiveEngineOutput.
  • corpora/observations.json and docs/CORPUS-MEASUREMENT.md.
  • The matrix entries at matrix.go:101 and docs/LANGUAGE-CAPABILITY-MATRIX.md:126.

Whether TestExtract_Instantiates, TestExtract_InstantiatesUnnamedTypeNoRef or TestGoFieldWritesWithholdCalls (internal/indexer/bindings_test.go) needs changes is open until the fix runs.

Run task golden:regen and task corpora:measure in the same PR.

What kind of improvement?

Correctness in an edge case

Would this change existing behavior?

Yes. Each composite-literal element adds a read reference, so these outputs change:

  • codegraph node and callers-style read queries list more readers.
  • Explore ranking changes, which regenerates the hugo goldens.

The output shapes stay the same. Only the set of read entries changes.

Before submitting
  • I searched existing issues and this is not a duplicate
  • I checked that the current behavior is not a deliberate decision in openspec/specs/

🤖 Generated with Claude Code

Ngôn ngữ chính
Go
Star
0
Fork
0
Merge trung bình
7 giờ 42 phút
Pull request đã merge (30 ngày)
111

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

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 seanb4t/codegraph-go

Tất cả issue của seanb4t/codegraph-go

Issue tương tự

Thêm issue về Go

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.