Comment #0 by paultjeadriaanse — 2021-04-23T16:53:24Z
The following code behaves differently, depending on whether the .a or the .b field is used.
The forum post may be more informative: https://forum.dlang.org/post/[email protected]
import std.stdio;
struct Apple(uint size) {
union {
int[size * size] a;
int[size][size] b;
}
static immutable typeof(this) pie = _pie();
private static typeof(this) _pie() pure {
typeof(this) result;
static foreach (i; 0 .. size)
static foreach (j; 0 .. size)
//result.a[i + j * size] = 1; // Works
result.b[i][j] = 1; // Fails
return result;
}
}
void main() {
Apple!(4) a = Apple!(4).pie;
writeln(a.a);
writeln(a.b);
}
Comment #1 by robert.schadek — 2024-12-13T19:15:53Z