Skip to content

fix(go): link a method value reached through a receiver field (#1566) - #4931

Merged
safishamsi merged 1 commit into
Graphify-Labs:v8from
nothariharan:fix/go-field-method-value
Nov 1, 2026
Merged

safishamsi merged 1 commit into
Graphify-Labs:v8from
nothariharan:fix/go-field-method-value

Conversation

@nothariharan

@nothariharan nothariharan commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Refs #1566. 61e864a (fix(go): link a method value passed as an argument as an indirect_call) links routing.Wrap(s.Health) to Server.Health. It does not link a method value reached through a field of the receiver, which is how Go code usually registers a handler held as a dependency:

// api/handler.go
package api

type ContextHandler struct{}

func (h *ContextHandler) Middleware(next int) int { return next }

// api/http_server.go
package api

type Macaron struct{}

func (m *Macaron) UseMiddleware(f func(int) int) {}

type HTTPServer struct {
	ContextHandler *ContextHandler
}

func (hs *HTTPServer) addMiddlewares(m *Macaron) {
	m.UseMiddleware(hs.ContextHandler.Middleware) // no edge to Middleware
}

On v8 (f5155bad, 0.9.100) the call edges are only addMiddlewares -> UseMiddleware (calls) plus references; there is no edge to ContextHandler.Middleware. Same result when HTTPServer is declared in a sibling file of the package. The real-world shape is Grafana pkg/api/http_server.go:732, m.UseMiddleware(hs.ContextHandler.Middleware).

Root cause

In extract_go's walk_calls, the method-value loop over call arguments added in 61e864a skips any selector_expression argument whose operand is not an identifier. hs.ContextHandler.Middleware has a selector_expression operand (hs.ContextHandler), so no raw call was recorded. The direct-call branch already handles the same shape (hs.ContextHandler.Middleware()) by recording the field as member_receiver and the receiver's type as field_owner, and _resolve_go_member_calls already types that through the caller's table or, for a struct declared in a sibling file, the owner's _go_fields (#3368).

The change

graphify/extractors/go.py only: the argument loop also accepts self.field.M when self is the enclosing method's own receiver, and records it with member_receiver = field, receiver_type = None, field_owner = self_type, the same values the direct-call branch uses. Resolution, guards and the emitted edge (indirect_call, context: "argument", INFERRED, 0.85) are unchanged code in _resolve_go_member_calls. A chain rooted at anything other than the method's own receiver is still skipped, as for direct calls.

Scope

  • Covered: field typed by a type of the same package, struct declared in the same file or in a sibling file.
  • Not covered here: a field typed from another package (*contexthandler.ContextHandler, the Grafana case). _go_single_type_name drops a qualified_type, so the field has no type on v8; that is what fix(go): resolve member calls on receivers typed from another package (#3368) #4853 adds, and this PR does not duplicate it. I applied fix(go): resolve member calls on receivers typed from another package (#3368) #4853's source diff together with this change in a scratch worktree: the cross-package repro then also gets addMiddlewares -> ContextHandler.Middleware (indirect_call) with no further change.
  • No AST cache schema bump: Go extraction output changes, so a cached Go file keeps the old raw calls until it is re-extracted. Left to the batch bump, as with the other recent Go fixes; happy to add one if preferred.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Tests or CI
  • Refactor
  • Security fix

Verification & Invariants

Invariant: a Go method value binds only to a method of the single type its receiver is declared as, and a value whose type is unknown links nothing and parks nothing (it may be a field, not a method). The new path goes through the same resolver and guards as a direct s.field.M() call, so it can only add an edge where the direct-call form would get one.

New tests in tests/test_go_method_value_indirect_calls.py:

  • test_a_method_value_through_a_receiver_field_is_an_indirect_call: same file; asserts indirect_call, INFERRED, no calls edge to Middleware, and the UseMiddleware call unchanged.

  • test_a_method_value_through_a_field_declared_in_a_sibling_file: struct declared in another file of the package.

  • test_a_method_value_through_a_field_of_unknown_type_links_and_parks_nothing: field typed *Missing (declared nowhere): no indirect_call, no unresolved_calls on the caller.

  • Read the CONTRIBUTING.md guide.

  • Reproduced the issue and identified the invariant.

  • Made the smallest fix necessary.

  • Added a regression test (if bug fix) or isolated boundary test.

  • Kept the PR description synchronized with the final implementation.

  • Documented any limitations / unsupported cases explicitly.

How was this tested?

# new tests, with the go.py change stashed (v8 behaviour)
uv run --frozen pytest -q tests/test_go_method_value_indirect_calls.py -p no:cacheprovider
  2 failed, 5 passed   (receiver_field, sibling_file fail; unknown-type guard passes)

# with the change
uv run --frozen pytest -q tests/test_go_method_value_indirect_calls.py -p no:cacheprovider
  7 passed

uv run --frozen pytest -q tests/ -k "go_" -p no:cacheprovider
  156 passed, 10 skipped

uv run --frozen python -m tools.skillgen --check
  check OK: 134 artifact(s) match committed output and expected/.

# full suite, Linux (WSL), uv sync --all-extras --frozen, HOME=$(mktemp -d)
uv run --frozen pytest tests/ -q --tb=short -p no:cacheprovider
  9365 passed, 28 skipped, 1 xfailed, 0 failed (15:42)

Ad-hoc repro (graphify.extract.extract(..., parallel=False)) for the three variants: same-package and sibling-file now emit addMiddlewares -> Middleware (indirect_call); cross-package emits it only with #4853 applied.

Graphify-specific checklist

  • I updated generated skill artifacts (uv run python -m tools.skillgen --bless) when changing their source fragments. (No skill source changed; --check passes.)
  • I confirmed that AST/structural extraction remains deterministic (no ambient state dependencies like ENV variables).
  • I reviewed changes for security implications (no unsafe interpolation into shell/Python).
  • I confirmed no API keys or local-only graph data are included.
  • (If applicable) I disclosed AI authorship in my commit messages.

…fy-Labs#1566)

61e864a records a method value passed as an argument (`routing.Wrap(s.Health)`)
as an indirect raw call, but only when its operand is a plain identifier. A
handler held as a field of the receiver, `m.UseMiddleware(hs.ContextHandler.Middleware)`,
has a selector operand, so it was skipped and the method got no edge.

The argument walk now also accepts `self.field.M` when `self` is the method's
own receiver, and records it the way the direct-call branch records
`self.field.M()`: the field as `member_receiver`, the receiver's type as
`field_owner`. _resolve_go_member_calls then types it through the caller's
table or the owner struct's fields in a sibling file (Graphify-Labs#3368) and emits the
INFERRED `indirect_call`. A field whose type is declared nowhere links and
parks nothing, as before.
@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

Thanks for the pull request, @nothariharan. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic.

@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Nov 1, 2026

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify reviewed this change.

No issues found by static checks — no coupling regressions or blocking issues in the code graph. That is not the same as safe to merge: see what was not checked.

Not checked: tests were not run; formal verification proved 0 of 1 changed function(s) (1 sampled, not proven).

Formal verification. PR-changed functions: 1/1 verified (0 proven, 1 may-equivalent, 0 distinguished) · 0 not verified.


Graphify review — findings

Extends Go method-value indirect-call detection to cover values reached through a field of the method's own receiver, e.g. m.UseMiddleware(hs.ContextHandler.Middleware). The field's declared type now types the receiver, the same way a direct hs.ContextHandler.Middleware() call already does, so Middleware gets an INFERRED indirect_call edge from the caller instead of no edge at all. Only self.field.Method is handled. Selectors rooted at any other identifier are skipped, and the raw call carries a new field_owner so the resolver can look up the field type, including one declared in a sibling file. If the field's type can't be resolved, no edge is emitted and nothing is parked as an unresolved call. New tests cover the same-file case, the sibling-file case, and the unknown-type case.

No blocking issues surfaced. 1 lower-confidence candidate did not survive cross-model review.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 69 functions depend on the 43 functions this change touches.

Health — grade B; 2 existing hotspot(s) in the area this change touches (pre-existing, not introduced here):

  • extract_go() — 19 callers, 13 callees (high)
  • walk() — 1 callers, 13 callees (high)

Verification — 69 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 69 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

4 of 487 test file(s) selected (1%) via static blast radius.

  • tests/test_go_method_value_indirect_calls.py — impact, changed-test
  • tests/test_go_type_alias.py — impact
  • tests/test_languages.py — impact
  • tests/test_multilang.py — impact

Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.

Formal verification

No difference found (not proven): No behavior difference found in extract\_go (not a proof).

The verifier ran both versions of extract\_go on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

@safishamsi
safishamsi merged commit 5f7d7e8 into Graphify-Labs:v8 Nov 1, 2026
14 checks passed
safishamsi added a commit that referenced this pull request Nov 1, 2026
… fixes

#4933 (python bare-call), #4931 (go method-value via field) and #4932 (go
var-init type refs) were merged on GitHub but each changes AST-cached
output and deferred its schema bump; one combined 33->34 bump so cached
Python/Go extractions re-run. #4929 (namespace packages) is a post-cache
pass and needs none. Opens the unreleased 0.9.101 changelog.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants