add core static value member support#638
Conversation
|
Warning Gemini encountered an error creating the review. You can try again by commenting |
There was a problem hiding this comment.
Summary
The PR introduces a clean, mutex-protected registry for associating const/var objects with named types. Generic-type origin normalization via staticMemberOrigin is handled consistently, and the integration into Member() correctly places static lookup ahead of regular method/field resolution without breaking the existing isType && kind != MemberMethod guard.
Three inline findings cover misleading panic messages and dead code. Two non-inline findings cover a missing symmetric test and the global registry lifetime.
Missing test — NewStaticMethod after NewStaticMember conflict (xgo_test.go)
The new guard added to NewStaticMethod (if lookupStaticMember(typ, name) != nil { ... }) has no direct test coverage. TestStaticMemberMethodConflict exercises the reverse direction only (static member after static method). A symmetric test would prevent regressions on this new guard.
Global registry lifetime (func_ext.go, staticMemberValues)
Unlike NewStaticMethod, which stores entries directly on the *types.Named via the Go type system (and is collected when the type is GC'd), staticMemberValues is a process-global map that never evicts entries. In long-lived processes that build many packages (e.g. a language server or batch compile server), this retains *types.Named pointers and their types.Object values indefinitely. Consider scoping the registry to a Package/builder instance, or documenting the lifetime trade-off with a comment on the global.
bd9a7f5 to
62b592e
Compare
62b592e to
b84da73
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #638 +/- ##
==========================================
+ Coverage 93.63% 93.70% +0.06%
==========================================
Files 29 29
Lines 7167 7240 +73
==========================================
+ Hits 6711 6784 +73
Misses 388 388
Partials 68 68 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
c9a7472 to
823891a
Compare
Summary
NewStaticMemberso package-level const/var objects can be associated with a named type and resolved through normalCodeBuilder.Memberhandling onTypeTypereceivers.Changes
NewStaticMemberfor registering static const/var members on named types.cb.Typ(T).MemberVal(...).cb.Typ(T).MemberRef(...)so assignable operations like inc/dec work.Origin()for static member lookup, soBox[int].namecan resolve members registered onBox[T].Testing
go test -run 'TestStaticMember|TestStaticMethod' ./...go test ./...git diff --check