www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21446] New: Cannot initialize a static array from a struct

https://issues.dlang.org/show_bug.cgi?id=21446

          Issue ID: 21446
           Summary: Cannot initialize a static array from a struct field
                    of dynamic array type at compile time
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Keywords: CTFE, rejects-valid
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: maxsamukha gmail.com

struct S {
    int[] a;
}

enum s = S(new int[1]);
int[1] a = s.a;

void main() {    
}

onlineapp.d(8): Error: cannot cast expression S([0]).a of type int[] to int[1]


Compiles if S is constructed directly in the initializer:

int[1] a = S(new int[1]).a; // ok

--
Dec 02 2020