Skip to content

Commit

Permalink
I want those hours of my life back please
Browse files Browse the repository at this point in the history
  • Loading branch information
Geod24 committed Mar 8, 2023
1 parent 17ab852 commit fa9447e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
10 changes: 10 additions & 0 deletions compiler/src/dmd/dinterpret.d
Original file line number Diff line number Diff line change
Expand Up @@ -2117,6 +2117,16 @@ public:
return CTFEExp.cantexp;
assert(e.type);

// There's a terrible hack in `dmd.dsymbolsem` that special case
// a struct will all zero to an `ExpInitializer(BlitExp(IntegerExp(0)))`
// There's matching code for it in e2ir (toElem's visitAssignExp),
// so we need the same hack here.
// This does not trigger for global as they get a normal initializer.
if (auto ts = e.type.isTypeStruct())
if (auto ae = e.isBlitExp())
if (ae.e2.op == EXP.int64)
e = ts.defaultInitLiteral(loc);

if (e.op == EXP.construct || e.op == EXP.blit)
{
AssignExp ae = cast(AssignExp)e;
Expand Down
9 changes: 9 additions & 0 deletions compiler/test/compilable/test17351.d
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// PERMUTE_ARGS: -preview=in
bool fun(S)(ref S[3] a) { assert(a == [42, 84, 169]); return true; }
bool fun2(S)(ref S a) { return true; }
void main()
Expand All @@ -14,4 +15,12 @@ void test2()
{
static immutable int[2] P = [ 0, 1 ];
static assert(f2(P) == 1);
immutable BigInt a, b;
static assert(glob1.twice == b.twice);
static assert(a.twice == b.twice);
}

struct BigInt { int[64] big; }
BigInt twice (in BigInt v) @safe pure nothrow @nogc { return v; }

immutable BigInt glob1 = BigInt.init;

0 comments on commit fa9447e

Please sign in to comment.