Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix phobos.sys.traits.isAggregateType to handle enums. #9089

Merged
merged 1 commit into from
Nov 23, 2024

Conversation

jmdavis
Copy link
Member

@jmdavis jmdavis commented Nov 23, 2024

The std.traits version does not take enums into account (and prior to this commit, neither does the phobos.sys version), but upon reflection, it seems like it's just likely to cause bugs if it doesn't take enums into account. Granted, enums whose base type is an aggregate type don't seem to be very common, but as a result of that, code that tests for aggregate types likely won't take them into account in the vast majority of cases, and I see no reason to not have the trait just deal with it rather than hoping that the user of the trait realizes that it's a potential issue, in which case, they would need to explicitly use OriginalType themselves to make it work for enums.

In addition, this way, OriginalType doesn't even get instantiated unless the type is actually an enum, whereas the correct solution that would most likely be used otherwise would be to just always do isAggregateType!(OriginalType!T) instead of isAggregateType!T.

I also put a ddoc comment on the unittest block, since I apparently missed it previously.

The std.traits version does not take enums into account (and prior to
this commit, neither does the phobos.sys version), but upon reflection,
it seems like it's just likely to cause bugs if it doesn't take enums
into account. Granted, enums whose base type is an aggregate type don't
seem to be very common, but as a result of that, code that tests for
aggregate types likely won't take them into account in the vast majority
of cases, and I see no reason to not have the trait just deal with it
rather than hoping that the user of the trait realizes that it's a
potential issue, in which case, they would need to explicitly use
OriginalType themselves to make it work for enums.

In addition, this way, OriginalType doesn't even get instantiated unless
the type is actually an enum, whereas the correct solution that would
most likely be used otherwise would be to just always do
isAggregateType!(OriginalType!T) instead of isAggregateType!T.

I also put a ddoc comment on the unittest block, since I apparently
missed it previously.
@jmdavis jmdavis added the Phobos 3 The PR is for Phobos V3. label Nov 23, 2024
@dlang-bot
Copy link
Contributor

Thanks for your pull request, @jmdavis!

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 + phobos#9089"

@dlang-bot dlang-bot merged commit 43f00ee into dlang:master Nov 23, 2024
9 checks passed
@jmdavis jmdavis deleted the pv3_aggregate branch November 23, 2024 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Merge:auto-merge Phobos 3 The PR is for Phobos V3.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants