feat: scope locals to their block in the type environment
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 52/100
Research direction
Start with LookupAt in internal/indexer/goextract/typeenv.go:89 and the test TestShadowedAliasResolvesByPosition in goextract/typeenv_test.go:92. Pick one of the name-only extractors, such as internal/indexer/mainstream/rustextract/typeenv.go:142, and add a shadow test where an inner-block local is followed by a call to the outer name. Done when that test passes and the outer name resolves after the block closes.
Written by the indexing model from the issue text.
Description
What exists today?
Each extractor's type environment finds a receiver's type by name. Four extractors also check the position of the call.
- Go:
internal/indexer/goextract/gotypeenv.go:146callsLookupAt. - TypeScript:
internal/indexer/tsextract/typeenv.go:139callsLookupAt. - Java:
internal/indexer/javaextract/typeenv.go:132callsLookupAt. - C#:
internal/indexer/csharpextract/typeenv.go:161callsLookupAt.
LookupAt is defined at internal/indexer/goextract/typeenv.go:89. It returns the latest declaration whose scope holds the position.
Seven other lookups use the name-only Lookup, which ignores the position:
- Python:
internal/indexer/pyextract/typeenv.go:164 - Ruby:
internal/indexer/mainstream/rubyextract/typeenv.go:96 - PHP:
internal/indexer/mainstream/phpextract/typeenv.go:163 - Kotlin:
internal/indexer/mainstream/kotlinextract/typeenv.go:164 - Swift:
internal/indexer/mainstream/swiftextract/typeenv.go:140 - Rust:
internal/indexer/mainstream/rustextract/typeenv.go:142 - C and C++:
internal/indexer/mainstream/cextract/typeenv.go:175
A whole-body lookup is wrong only where the language ends a local at a block. Kotlin, Swift, Rust, C and C++ do. Ruby ends a local at a do or brace block, but not at if. Python and PHP have no block scope, so a local hides an outer name for the whole function. internal/indexer/goextract/scope.go:68 records the PHP rule.
No fixture covers a block-scoped shadow in these seven extractors yet.
How does it behave now?
Reading internal/indexer/mainstream/rustextract/typeenv.go:142, the lookup ignores the block. A local declared in an inner block still answers a call after that block closes. This is from reading the code. A run of the Rust extractor on a shadow fixture has not been done.
How should it behave?
Each extractor scopes a local by its language's rule:
- Kotlin, Swift, Rust, C and C++: from the declaration to the end of the enclosing block.
- Ruby: from the declaration to the end of the enclosing
door brace block. - Python and PHP: whole-function scope, which the language defines.
A call resolves to the declaration whose scope holds its position, as LookupAt does for Go. A call after an inner block resolves to the outer name again.
Add one shadowing test per extractor, modelled on TestShadowedAliasResolvesByPosition at internal/indexer/goextract/typeenv_test.go:92. Each test declares an inner-block local, then calls the outer name after the block. The test asserts the outer resolution. The Python and PHP tests assert whole-function scope, so the rule stays fixed.
The spec in openspec/specs/graph-index/spec.md already requires this. Its requirement is "A same-file reference resolves by lexical scope." The design of the per-body type environment is in openspec/changes/archive/2026-11-02-index-invariants/design.md, decision D17.
Would this change existing behavior?
Yes. Some calls that resolve today to an inner-block local will resolve to the outer name, or stay unresolved. The output shape does not change.
What kind of improvement?
Correctness in an edge case
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/
- Dominant language
- Go
- Stars
- 0
- Forks
- 0
- Avg merge
- 5h 16m
- Merged PRs (30d)
- 107
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from seanb4t/codegraph-go
-
area:indexer bug needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
seanb4t/codegraph-go#385 ·
Maintainers usually reply within 1 day
-
chore needs-triage
Difficulty 1/5 Under an hour Newbie friendliness 88/100
seanb4t/codegraph-go#380 ·
Maintainers usually reply within 1 day
-
chore needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
seanb4t/codegraph-go#379 ·
Maintainers usually reply within 1 day
-
chore needs-triage
Difficulty 1/5 1-3 hours Newbie friendliness 84/100
seanb4t/codegraph-go#362 ·
Maintainers usually reply within 1 day
-
area:query bug priority:low spec-needed
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
seanb4t/codegraph-go#355 ·
Maintainers usually reply within 1 day
All issues in seanb4t/codegraph-go
Similar issues
-
enhancement exporter/awskinesis needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
open-telemetry/opentelemetry-collector-contrib#53334 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
erigontech/erigon#26523 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 83/100
SocialGouv/iterion#3376 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
seaweedfs/seaweedfs#12740 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day