feat: scope locals to their block in the type environment
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 52/100
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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/
- 主要语言
- Go
- 星标
- 0
- 派生
- 0
- 平均合并
- 7 小时 42 分钟
- 30 天内合并 PR
- 111
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
seanb4t/codegraph-go 的其他 Issue
-
chore needs-triage
难度 1/5 1 小时以内 新手友好度 88/100
seanb4t/codegraph-go#380 ·
维护者通常 1 天内回复
-
chore needs-triage
难度 2/5 1-3 小时 新手友好度 82/100
seanb4t/codegraph-go#379 ·
维护者通常 1 天内回复
-
area:query chore needs-triage spec-needed
难度 2/5 1-3 小时 新手友好度 74/100
seanb4t/codegraph-go#377 ·
维护者通常 1 天内回复
-
chore needs-triage
难度 1/5 1-3 小时 新手友好度 84/100
seanb4t/codegraph-go#362 ·
维护者通常 1 天内回复
-
area:query bug needs-triage
难度 2/5 1-3 小时 新手友好度 80/100
seanb4t/codegraph-go#355 ·
维护者通常 1 天内回复
查看 seanb4t/codegraph-go 的全部 Issue
相似的 Issue
-
go-vulnerability security-scan
难度 1/5 1 小时以内 新手友好度 84/100
teslashibe/agent-go#35 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
alecthomas/chroma#1498 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 83/100
维护者通常 8 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
-
难度 2/5 1-3 小时 新手友好度 77/100
维护者通常 1 天内回复