Fix Bugzilla issue 24875 (#9090)

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.
This commit is contained in:
Jonathan M Davis 2024-11-23 17:02:11 -07:00 committed by GitHub
parent 43f00ee83d
commit aee681c468
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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);
@ -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);
}
/**