Skip to content

Add getMemberAttributes and getMemberType traits#22545

Draft
CyberShadow wants to merge 1 commit intodlang:masterfrom
CyberShadow:add-getMember-lightweight-traits
Draft

Add getMemberAttributes and getMemberType traits#22545
CyberShadow wants to merge 1 commit intodlang:masterfrom
CyberShadow:add-getMember-lightweight-traits

Conversation

@CyberShadow
Copy link
Member

Generated by Claude Opus 4.6, usual disclaimers apply.

Alternative to #22541 / #22542.

CC @dkorpel


New lightweight traits for member introspection that use sym.search() instead of full expressionSemantic, avoiding circular dependency errors when iterating allMembers on types with auto-return methods.

__traits(getMemberAttributes, T, "name") returns UDAs on the named member. __traits(getMemberType, T, "name") returns the member's type, usable in is() expressions for return type extraction, function type checks, etc.

New lightweight traits for member introspection that use sym.search()
instead of full expressionSemantic, avoiding circular dependency errors
when iterating allMembers on types with auto-return methods.

__traits(getMemberAttributes, T, "name") returns UDAs on the named member.
__traits(getMemberType, T, "name") returns the member's type, usable in
is() expressions for return type extraction, function type checks, etc.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@dlang-bot
Copy link
Contributor

Thanks for your pull request, @CyberShadow!

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#22545"

Comment on lines +1353 to +1357
if (fd.overnext)
{
deprecation(e.loc, "`__traits(getMemberAttributes)` may only be used for individual functions, not the overload set `%s`", fd.toChars());
deprecationSupplemental(e.loc, "the result of `__traits(getOverloads)` may be used to select the desired function to extract attributes from");
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Seems weird to emit deprecation warnings from a new feature. However, this is what getMember does today, so this copies its behavior to remain consistent.

Which does raise the question of what to do with overload sets. We could also add getOverloadAttributes, getOverloadType, etc. granting the same benefit as this (eliding full semantic analysis), but it becomes a quadratic explosion of traits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI Generated Code that is generated by an LLM AI.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants