Repository navigation
Add attribute bag to AST nodes and a public typescope package - #10
Merged
Merged
Conversation
Every node embeds AttributeBag, so a resolver can store post-parse metadata (such as an inferred type) on a node via SetAttribute / GetAttribute without widening node constructors. Equal keeps go-cmp node comparisons working past the bag's unexported map.
Resolves the static type of a value expression by tracing it through the function scopes of a class subtree. Promoted from an internal package so any project on the parser can reuse it.
TomasVotruba
force-pushed
the
node-attribute-bag-and-typescope
branch
from
November 8, 2026 19:40
91be7cd to
7d3dc55
Compare
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.
Foundation for carrying resolved types on the AST, reusable across projects on this parser.
1. Attribute bag on every node
AttributeBag(embedded in all 166node.gonodes plus the transient parser nodes ininternal/php5|7|8) gives every nodeSetAttribute(key, value)/GetAttribute(key).Vertexgains the two methods.AttributeBag.Equalkeepsgo-cmpnode comparisons (the parser test suite) working past the bag's unexported map.A resolver can now stamp an inferred type onto a property fetch, variable or method call node and read it back later, instead of recomputing it.
2. Public typescope package
pkg/typescoperesolves the static type of a value expression by tracing it through the function scopes of a class subtree (typed params, single assignments,$this->propertydeclared types, builtin call/arithmetic result types).Scope is single-object native types; docblocks and union types are deliberately out.
Tests
go test ./...green.gofmt -s, golangci-lint (0 issues), modernize clean on changed packages.