Issue 21446 - Cannot initialize a static array from a struct field of dynamic array type at compile time
Summary: Cannot initialize a static array from a struct field of dynamic array type at...
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P3 normal
Assignee: No Owner
URL:
Keywords: CTFE, rejects-valid
Depends on:
Blocks:
 
Reported: 2020-12-02 14:54 UTC by Max Samukha
Modified: 2024-11-24 20:21 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Max Samukha 2020-12-02 14:54:47 UTC
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
Comment 1 Nick Treleaven 2024-11-24 20:21:42 UTC
Workaround - use `[]`:

int[1] a = s.a[];