Bug 21570 – __traits(isStaticArray, ...) accepts enums with static array as base type
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-01-21T14:19:29Z
Last change time
2022-03-23T17:27:35Z
Assigned to
No Owner
Creator
moonlightsentinel
Comments
Comment #0 by moonlightsentinel — 2021-01-21T14:19:29Z
Example:
-----------------------------------------------------------------
enum EnumArray : int[2] {
a = [ 1, 2 ],
b = [ 3, 4 ]
}
static assert(!__traits(isStaticArray, EnumArray)); // Fails
// Expected equal behaviour of trait and is-expression
static assert(!is(EnumArray == T[n], T, size_t n)); // Passes
-----------------------------------------------------------------
The spec[1] states that a named enum creates a distinct type which is implicitly convertible to it's base type. So EnumArray is not a static array and __traits(isStaticArray, EnumArray) should yield `false` as done for the equivalent is-expression.
[1] https://dlang.org/spec/enum.html#named_enums
Comment #1 by dlang-bot — 2021-01-21T15:29:45Z
@MoonlightSentinel created dlang/phobos pull request #7760 "Make isAutoDecodableString independent of issue 21570" mentioning this issue:
- Make isAutoDecodableString independent of issue 21570
The current implementation relies on issue 21570 to reject enums with
static arrays as their base type.
Use another is-expression instead of `isStaticArray` to detect types
that are (convertible to) static arrays.
See https://issues.dlang.org/show_bug.cgi?id=21570https://github.com/dlang/phobos/pull/7760
Comment #2 by dlang-bot — 2021-01-21T23:21:22Z
dlang/phobos pull request #7760 "Make isAutoDecodableString independent of issue 21570" was merged into master:
- 7c13ddf8de6bbaf287a60ebac7e3f31acf45ecec by MoonlightSentinel:
Make isAutoDecodableString independent of issue 21570
The current implementation relies on issue 21570 to reject enums with
static arrays as their base type.
Use another is-expression instead of `isStaticArray` to detect types
that are (convertible to) static arrays.
See https://issues.dlang.org/show_bug.cgi?id=21570https://github.com/dlang/phobos/pull/7760
Comment #3 by dlang-bot — 2021-01-23T19:37:42Z
@MoonlightSentinel updated dlang/dmd pull request #12142 "Fix 21570 - __traits(isStaticArray, ...) accepts enums with static..." mentioning this issue:
- Issue 21570 - Deprecate __traits(isStaticArray, ...) accepts enums
...with static array as base type.
The spec[1] states that a named enum creates a distinct type which is
implicitly convertible to it's base type. Hence `__traits(isStaticArray, <enum>)`
should yield `false` as done for an equivalent `is(...)` expression.
[1] https://dlang.org/spec/enum.html#named_enumshttps://github.com/dlang/dmd/pull/12142