Bug 24875 – std.traits.isAggregateType does not consider enums of aggregate types to be aggregate types

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2024-11-23T12:19:12Z
Last change time
2024-11-24T00:02:17Z
Keywords
pull
Assigned to
No Owner
Creator
Jonathan M Davis

Comments

Comment #0 by issues.dlang — 2024-11-23T12:19:12Z
The second assertion fails: --- import std.traits; struct S {} enum ES : S { a = S.init } static assert( isAggregateType!S); static assert( isAggregateType!ES); --- Looking at std.traits.isAggregateType, it does not take enums into account, and the kind of code that tests for whether a type is an aggregate type is almost certainly going to want to consider enums whose base type is an aggregate type as an aggregate type, meaning that right now, the correct way to use isAggregateType is almost certainly going to be isAggregateType!(OriginalType!T)), which I'm guessing almost no code does. This likely has not come up previously either due to the fact that isAggregateType almost certainly isn't needed very often - or due to the fact that enums whose base type is an aggregate type seem to be quite rare in D (many people seem to not know that you even _can_ do it). But from what I can tell, there really isn't a good reason not to consider an enum with a base type that's an aggregate type as an aggregate type, and most people are not going to think of enums possibly being an aggregate type, meaning that while the current situation arguably is not actually a bug, it certainly makes it easy to introduce bugs. Fortunately, I'm pretty sure that this is the kind of change that we can make without breaking code, and it might actually fix some subtle bugs in Phobos related to the few places that use isAggregateType.
Comment #1 by dlang-bot — 2024-11-23T12:38:51Z
@jmdavis created dlang/phobos pull request #9090 "Fix Bugzilla issue 24875" fixing this issue: - Fix Bugzilla issue 24875 This makes it so that enums whose base type is an aggregate type are also considered an aggregate type. It probably doesn't affect much code, since isAggregateType isn't needed often, and it's fairly rare to declare enums whose base type is an aggregate type, but in general, code that cares whether a type is an aggregate type is going to care that an enum's base type is an aggregate type. https://github.com/dlang/phobos/pull/9090
Comment #2 by dlang-bot — 2024-11-24T00:02:17Z
dlang/phobos pull request #9090 "Fix Bugzilla issue 24875" was merged into master: - 512e10041b5aef2320df523df73052cfcc27b1c9 by Jonathan M Davis: Fix Bugzilla issue 24875 This makes it so that enums whose base type is an aggregate type are also considered an aggregate type. It probably doesn't affect much code, since isAggregateType isn't needed often, and it's fairly rare to declare enums whose base type is an aggregate type, but in general, code that cares whether a type is an aggregate type is going to care that an enum's base type is an aggregate type. https://github.com/dlang/phobos/pull/9090