fix(typecheck): resolve indexed writes at the field path they target - #42
Merged
Merged
Conversation
Flow widening for a dynamic index write resolved the container from the path's root symbol instead of the path itself, so `a.b[k] = v` stored a type derived from `a` under the path key for `a.b`. Every read of `a.b` sharing that SSA version then reported the enclosing record's type. Resolve the container, its predecessor versions and its declared template at the full path, and apply the same path-aware declared lookup to map element reads and iterator sources. Widening now reaches real declared containers, so restrict value-domain widening to values the container cannot already hold.
skhaz
self-requested a review
September 9, 2026 00:08
skhaz
approved these changes
Sep 9, 2026
skhaz
approved these changes
Sep 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Defect
An element assignment through a record field path later in a function (
r.kinds[1] = x) makes every earlier read ofr.kindson that flow version resolve to the enclosing record type. Reproduction: a library exportingtype Report = {kinds: {string}, sources: {string}}anddescribe(): Report; a caller doingRemoving the assignment, or assigning through a local, removes the error.
Cause
Flow widening for a dynamic index write resolved the container from the path's root symbol instead of the path itself, so
a.b[k] = vcomputed a widened type fromaand stored it under the path key fora.b.Fix
types/flow/transfer.go:processIndexerAssignmentReturnKeyresolves the container type at the full path; predecessor joins are keyed by the path's segments;declaredTypeAtPathwalks segments through the root declaration;mergeMapValueDomainkeeps a declared map value domain from unioning with its own refinement.TestIndexedFieldElementWriteKeepsFieldType,TestIndexedFieldElementWriteKeepsFieldTypeAcrossModules,TestDeclaredMapFieldIndexerWriteKeepsValueType.go test ./...andgo vetclean. Found while linting Bee (Wippy application) underwippy lint; the runtime pins go-lua v1.5.19 and needs a release plus bump to pick this up.