D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 21570 - __traits(isStaticArray, ...) accepts enums with static array as base type
Summary: __traits(isStaticArray, ...) accepts enums with static array as base type
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-01-21 14:19 UTC by moonlightsentinel
Modified: 2022-03-23 17:27 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description moonlightsentinel 2021-01-21 14:19:29 UTC
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 Dlang Bot 2021-01-21 15:29:45 UTC
@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=21570

https://github.com/dlang/phobos/pull/7760
Comment 2 Dlang Bot 2021-01-21 23:21:22 UTC
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=21570

https://github.com/dlang/phobos/pull/7760
Comment 3 Dlang Bot 2021-01-23 19:37:42 UTC
@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_enums

https://github.com/dlang/dmd/pull/12142