Skip to content

fix(go-lsp): follow a type alias declared in another file of the package - #2769

Merged
DeusData merged 5 commits into
DeusData:mainfrom
gaurav0107:fix/2033-go-type-alias-alias-of-is-never-register
Oct 29, 2026
Merged

DeusData merged 5 commits into
DeusData:mainfrom
gaurav0107:fix/2033-go-type-alias-alias-of-is-never-register

Conversation

@gaurav0107

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #2033. A Go identity alias declared in one file of a package is now followed when a method is called through it from another file.

alias_of was only set by the per-file AST scan in go_lsp.c, and that scan only sees the file it walks. The def-driven registration that builds the cross-file registries had nothing to copy, because neither CBMDefinition nor CBMLSPDef carried an alias target. With receiver-qualified method QNs (#1913), the issue's shape now drops the edge entirely. I reproduced it on main with a three-file package:

// fs/bitmap.go
type bitmap []uint64
func (b bitmap) Set(i int) { ... }
// fs/featureset.go
type FeatureSet = bitmap
// fs/framework.go
func Use(f *Framework) { reqs := f.NewFeatureSet(); reqs.Set(3) }

On main, Use has a CALLS edge to NewFeatureSet and none to Set. On this branch it also has Use -> fs.bitmap.Set, confidence 0.95. A same-package decoy other.Set gets no edge.

Changes:

  • extract_defs.c: a Go type_alias def records its type field text in the new tail field CBMDefinition.alias_target. A defined type type A B is a type_spec, so it never gets one and keeps its own method set.
  • pass_lsp_cross.c copies it into the new CBMLSPDef.alias_target. result_compact.c and the memory census in pipeline.c cover the new string.
  • go_lsp.c: both cross-file registrars (cbm_run_go_lsp_cross and cbm_go_build_cross_registry) set rt.alias_of through go_alias_target_qn. Only a bare identifier target is qualified, as <def module>.<name>, which is a type in the same package. A pkg.T, *T, composite or generic target stays unset rather than guessed. The same-file scan is unchanged.
  • lsp_surface.c: the persisted surface carries the field as "al", so SURFACE_CODEC_VERSION goes from 3 to 4. Existing caches re-extract once, and an incremental run sees the same alias as a full one. This follows the precedent of 36bce46. The literal version-3 surfaces in the codec tests move to 4.

Something you may want to know: the resolved call is reported as lsp_embed_dispatch, because the method's receiver (bitmap) differs from the variable's type (FeatureSet). A same-file alias gets the same label on main today (I checked with a one-file fixture). I left that labelling alone to keep this PR to the issue.

Out of scope: cross-package alias targets (type A = other.B). Qualifying those needs the defining file's import map, which the def-driven registries don't have.

Tests

  • golsp_crossfile_type_alias_method and golsp_crossfile_type_alias_method_prebuilt (tests/test_go_lsp.c) cover the per-file cross registry and the prebuilt one the parallel resolver shares. Each checks that reqs.Set binds exactly test.main.bitmap.Set with a typed lsp_* strategy despite a same-named other.Set. A defined type Defined (no alias target) must not bind bitmap.Set.
  • pipeline_go_crossfile_type_alias_method and _parallel (tests/test_pipeline.c, next to pipeline_go_multi_return_receiver_is_typed) index the three-file package above. They expect exactly one CALLS edge Use -> Set into fs/bitmap.go with an lsp_ strategy, and none into the decoy's file.

Evidence

Machine: Amazon Linux 2023, x86_64, clang 15.0.7 (ASan+UBSan via the default scripts/test.sh flags).

main + the pipeline tests (worktree of upstream/main):
  CBM_TEST_ONLY=<the two new tests + pipeline_go_multi_return_receiver_is_typed>
  scripts/test.sh --suites pipeline CC=clang CXX=clang++
    1 passed, 2 failed
    pipeline_go_crossfile_type_alias_method           FAIL  Use -> Set: right=0 decoy=0 lsp=0
    pipeline_go_crossfile_type_alias_method_parallel  FAIL  Use -> Set: right=0 decoy=0 lsp=0

this branch:
  scripts/test.sh --suites "go_lsp pipeline extraction incremental lsp_resolution_probe parallel" CC=clang CXX=clang++
    1288 passed
  scripts/test.sh --suites "cli integration mcp lang_contract cross_repo repro_lsp_ordered_signatures repro_lsp_ordered_local edge_types_probe node_creation_probe" CC=clang CXX=clang++
    1039 passed, 4 skipped (Windows-only platform skips)
  scripts/check-dco.sh upstream/main..HEAD   OK
  scripts/check-no-test-skips.sh             OK

I also built the binary (make -f Makefile.cbm cbm), indexed the fixture, then appended a line to fs/framework.go and indexed again. The second run takes the incremental path, where the alias comes from the persisted surface. Both runs return Use -> fs.bitmap.Set (lsp_embed_dispatch, 0.95).

Not verified locally

  • scripts/lint.sh --ci: cppcheck and clang-format-20 aren't installed here. git diff -U0 upstream/main..HEAD | clang-format-diff -p1 (clang-format 15) is empty.
  • I didn't run the full default scripts/test.sh venue run (about 2h on this machine). I ran only the suites listed above.
  • I haven't run it against the kubernetes corpus from the issue.

Checklist

  • Every commit is signed off (git commit -s): scripts/check-dco.sh upstream/main..HEAD OK
  • Tests pass locally (make -f Makefile.cbm test): the suites listed above pass; the full venue run was not run locally
  • Lint passes (make -f Makefile.cbm lint-ci): not run locally (see above)
  • New behavior is covered by a test (reproduce-first for bug fixes)

🤖 Opened with Superhuman, an open-source contribution agent.

`CBMRegisteredType.alias_of` is followed by the method lookup
(go_lookup_field_or_method_depth), but only the per-file AST scan ever
set it, and that scan only sees the file it walks. The def-driven
registration that builds the cross-file registries had no alias target
to copy, because neither CBMDefinition nor CBMLSPDef carried one. So a
`type FeatureSet = bitmap` in one file was invisible to `reqs.Set()` in
another. Since receiver-qualified method QNs (DeusData#1913), the call no longer
resolves by name coincidence either, and it got no CALLS edge at all.

The Go extractor now records the aliased type text of a `type A = B`
(CBMDefinition.alias_target). pass_lsp_cross copies it into CBMLSPDef,
and both cross-file registrars (cbm_run_go_lsp_cross and
cbm_go_build_cross_registry) qualify it against the def's module and
set alias_of. Only a bare identifier target is qualified, which is a
type in the same package. A qualified, pointer, composite or generic
target is left unset rather than guessed. A defined type `type A B` is
a type_spec, so it never gets an alias target and keeps its own method
set.

The persisted LSP surface carries the new field ("al"), so
SURFACE_CODEC_VERSION goes from 3 to 4: existing caches re-extract once,
and an incremental run sees the same alias as a full one. The literal
version-3 surfaces in the codec tests move to 4.

Tests: golsp_crossfile_type_alias_method (+_prebuilt) check both
registries, with a same-named decoy and a defined-type negative.
pipeline_go_crossfile_type_alias_method (+_parallel) index the
three-file package from the issue. Before the fix, Use had no CALLS
edge to Set.

Fixes DeusData#2033

Signed-off-by: Gaurav Dubey <gauravdubey0107@gmail.com>
@github-actions

Copy link
Copy Markdown

Thanks for opening this — it has been seen, and it is queued.

This note is automated, but it is not a brush-off: it exists so you know where your PR stands instead of having to guess from silence.

Current review status: working through a backlog. 0.9.1-rc.1 is out, so the release freeze that held reviews is over — but it left a large queue of open pull requests behind it, and we are reading through them oldest-first. The background is in discussion #1144.

What that means for this PR, concretely:

  • It will not be closed for inactivity. No stale bot touches pull requests here.
  • It may still sit a while before a human reads it. That is on us, not on you.
  • Older PRs are read first, so a recent one is not being skipped — it is behind a queue.

Things that will genuinely speed it up whenever review does happen:

  • Keep it rebased on main — the tree is moving quickly right now, and a conflicting branch cannot be reviewed as the diff you intended.
  • Get CI green, or say which failures you believe are pre-existing.
  • Keep the change to one claim. Bundled features and refactors get split before they get merged, which costs you a round trip.
  • Every commit needs a sign-off (git commit -s) — CI enforces DCO.

If this fixes a bug, a reproduction we can run is worth more than a description of the symptom.

Thanks for contributing, and sorry in advance for the wait.

@gaurav0107
gaurav0107 marked this pull request as ready for review October 22, 2026 13:07
@gaurav0107
gaurav0107 requested a review from DeusData as a code owner October 22, 2026 13:07
@DeusData DeusData added bug Something isn't working parsing/quality Graph extraction bugs, false positives, missing edges labels Oct 25, 2026
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
@DeusData

Copy link
Copy Markdown
Owner

Thank you, Gaurav - this is exactly the fix #2033 asked for, carried through both cross-file registries, with identity aliases kept strictly apart from defined types. The red ci-ok on the previous run was an aggregation-timing hiccup in our CI (it read two jobs as still running a few seconds after they had finished green); all ten selected lanes, including your new go_lsp and pipeline tests, passed. Main has also changed two of the files you touch, so we merged current main into your branch (one signed-off merge commit, f8b2f36; your commit is unchanged) for a fresh run. Please pull before pushing again. We will merge once the checks are green.

@gaurav0107

Copy link
Copy Markdown
Contributor Author

Thanks for the review and for merging main in. I'll pull f8b2f36 before pushing anything else to this branch.

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
@DeusData

Copy link
Copy Markdown
Owner

Thanks again, @gaurav0107. Several other pull requests landed on main this evening, including changes in files this one also touches, so we merged current main into your branch once more (one signed-off merge commit, a2feed8; your changes are untouched). That keeps the required checks honest against today's tree; we will merge once they are green. Please pull before pushing again.

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
@DeusData

Copy link
Copy Markdown
Owner

Thank you for your patience, @gaurav0107. CI went green on this branch, but tonight's merges on main touched tests/test_pipeline.c, which this pull request also changes, so that green no longer covered today's main. We merged current main into the branch once more (one merge commit, 1306c27; your changes are untouched) and will merge once the fresh checks are green. Please pull before pushing again.

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
@DeusData

Copy link
Copy Markdown
Owner

Thank you for your patience, @gaurav0107. CI went green on this branch, but this evening's merges on main touched files this pull request also changes, so that green no longer covered today's main. We merged current main into the branch once more (one merge commit, ba246da; your changes are untouched) and will merge once the fresh checks are green. Please pull before pushing again.

@gaurav0107

Copy link
Copy Markdown
Contributor Author

Thanks @DeusData for keeping the branch current with main through a2feed8, 1306c27 and ba246da, and for re-running the checks. I'll pull ba246da before pushing anything else to this branch. Nothing further from my side unless the fresh CI run turns something up.

@DeusData
DeusData merged commit 7b398de into DeusData:main Oct 29, 2026
26 checks passed
@DeusData

Copy link
Copy Markdown
Owner

Merged as 7b398de - thank you, @gaurav0107! The Go LSP now follows a type alias declared in another file of the same package, so calls through the alias resolve to the aliased type's methods. Thank you for the focused fix and for your patience through the branch refreshes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working parsing/quality Graph extraction bugs, false positives, missing edges

Projects

None yet

Development

Successfully merging this pull request may close these issues.

go: type alias alias_of is never registered across files — aliased receiver methods resolve by name coincidence only

2 participants