www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19639] New: Initializing static array with slice enum of


          Issue ID: 19639
           Summary: Initializing static array with slice enum of different
                    length crashes the compiler
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: regression
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: kinke gmx.net

enum EMPTY_STRING = "\0"[0..0];
void main() { char[64] buf = EMPTY_STRING; }

According to https://run.dlang.io/is/zQsYSf, this results in runtime errors for
v2.060-65 ('array length mismatch'), compiles successfully (!) for v2.066-70,
and crashes the compiler since 2.071.

Note that `void main() { char[64] buf = "\0"[0..0]; }` results in runtime
errors for all tested versions.

A non-empty slice `enum EMPTY_STRING = "\0"[0..1]` compiles successfully (!)
since v2.066, while previous versions and `void main() { char[64] buf =
"\0"[0..1]; }` yield runtime errors.

It's not just initializations, but assignments too (`void main() { char[64]
buf; buf = EMPTY_STRING; }`).

Originally posted here: https://github.com/ldc-developers/ldc/issues/2882

Feb 02 2019