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 Issue 21103 - isDynamicArray instantiates unecessary templates #7574

Merged
merged 1 commit into from
Jan 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 31 additions & 1 deletion std/traits.d
Original file line number Diff line number Diff line change
Expand Up @@ -6849,7 +6849,19 @@ enum bool isStaticArray(T) = __traits(isStaticArray, T);
/**
* Detect whether type `T` is a dynamic array.
*/
enum bool isDynamicArray(T) = is(DynamicArrayTypeOf!T) && !isAggregateType!T;
template isDynamicArray(T)
{
static if (is(T == U[], U))
enum bool isDynamicArray = true;
else static if (is(T U == enum))
// BUG: isDynamicArray / isStaticArray considers enums
// with appropriate base types as dynamic/static arrays
// Retain old behaviour for now, see
// https://github.com/dlang/phobos/pull/7574
enum bool isDynamicArray = isDynamicArray!U;
else
enum bool isDynamicArray = false;
}

///
@safe unittest
Expand All @@ -6873,6 +6885,24 @@ enum bool isDynamicArray(T) = is(DynamicArrayTypeOf!T) && !isAggregateType!T;
static assert(!isDynamicArray!( SubTypeOf!(Q!T) ));
}
}

static assert(!isDynamicArray!(int[5]));

static struct AliasThis
{
int[] values;
alias values this;
}

static assert(!isDynamicArray!AliasThis);

// https://github.com/dlang/phobos/pull/7574/files#r464115492
enum E : string
{
a = "a",
b = "b",
}
static assert( isDynamicArray!E);
}

/**
Expand Down