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.
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.68% +0.04%
==========================================
Files 29 29
Lines 7167 7221 +54
==========================================
+ Hits 6711 6765 +54
Misses 388 388
Partials 68 68 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
c9a7472 to
823891a
Compare
823891a to
c9a1de6
Compare
|
Does it seem like simply upgrading NewStaticMethod/TyStaticMethod to NewStaticMember/TyStaticMember would solve the problem? |
|
In addition, XGo's engineering guidelines discourage defensive programming, such as |
c9a1de6 to
521638e
Compare
You're right. Now I just upgraded NewStaticMethod/TyStaticMethod to NewStaticMember/TyStaticMembe. Besides, I kept Could you confirm which direction you prefer here: should we keep this compatibility layer for existing users, or remove |
remove them directly |
521638e to
1bf0f5a
Compare
Okay, it's clean now |
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