Skip to content

add core static value member support#638

Open
KurodaKayn wants to merge 4 commits into
goplus:mainfrom
KurodaKayn:static-value-member-core
Open

add core static value member support#638
KurodaKayn wants to merge 4 commits into
goplus:mainfrom
KurodaKayn:static-value-member-core

Conversation

@KurodaKayn

Copy link
Copy Markdown

Summary

  • Add the core static value member path for named types.
  • This introduces NewStaticMember so package-level const/var objects can be associated with a named type and resolved through normal CodeBuilder.Member handling on TypeType receivers.
  • Part of support static value members for named types #637

Changes

  • Add NewStaticMember for registering static const/var members on named types.
  • Resolve registered static value members from cb.Typ(T).MemberVal(...).
  • Resolve registered static var members from cb.Typ(T).MemberRef(...) so assignable operations like inc/dec work.
  • Keep static methods and static value members in the same member namespace by rejecting collisions.
  • Normalize generic instantiated named types to Origin() for static member lookup, so Box[int].name can resolve members registered on Box[T].

Testing

  • go test -run 'TestStaticMember|TestStaticMethod' ./...
  • go test ./...
  • git diff --check

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

@fennoai fennoai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread func_ext.go Outdated
Comment thread func_ext.go Outdated
Comment thread func_ext.go
@KurodaKayn KurodaKayn force-pushed the static-value-member-core branch from 62b592e to b84da73 Compare June 24, 2026 03:36
@codecov

codecov Bot commented Jun 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.70%. Comparing base (4e08570) to head (823891a).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@KurodaKayn KurodaKayn force-pushed the static-value-member-core branch from c9a7472 to 823891a Compare June 24, 2026 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant