Skip to content

Commit

Permalink
Fix Bugzilla issue 24875 (#9090)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jmdavis authored Nov 24, 2024
1 parent 43f00ee commit aee681c
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions std/traits.d
Original file line number Diff line number Diff line change
Expand Up @@ -7251,16 +7251,21 @@ alias PointerTarget(T : T*) = T;
/**
* Detect whether type `T` is an aggregate type.
*/
enum bool isAggregateType(T) = is(T == struct) || is(T == union) ||
is(T == class) || is(T == interface);
template isAggregateType(T)
{
static if (is(T == enum))
enum isAggregateType = isAggregateType!(OriginalType!T);
else
enum isAggregateType = is(T == struct) || is(T == class) || is(T == interface) || is(T == union);
}

///
@safe unittest
{
class C;
union U;
struct S;
interface I;
class C {}
union U {}
struct S {}
interface I {}

static assert( isAggregateType!C);
static assert( isAggregateType!U);
Expand All @@ -7271,6 +7276,16 @@ enum bool isAggregateType(T) = is(T == struct) || is(T == union) ||
static assert(!isAggregateType!(int[]));
static assert(!isAggregateType!(C[string]));
static assert(!isAggregateType!(void delegate(int)));

enum ES : S { a = S.init }
enum EC : C { a = C.init }
enum EI : I { a = I.init }
enum EU : U { a = U.init }

static assert( isAggregateType!ES);
static assert( isAggregateType!EC);
static assert( isAggregateType!EI);
static assert( isAggregateType!EU);
}

/**
Expand Down

0 comments on commit aee681c

Please sign in to comment.