Skip to content
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions compiler/src/dmd/ctfeexpr.d
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,16 @@ bool needToCopyLiteral(const Expression expr) nothrow
}
}

private Expressions* copyLiteralArray(Expressions* oldelems, Expression basis = null)
// oldelems can have a null element e.g. for `ArrayLiteralExp.elements` when `basis` is set
private Expressions* copyLiteralArray(Expressions* oldelems)
{
if (!oldelems)
return oldelems;
incArrayAllocs();
auto newelems = new Expressions(oldelems.length);
foreach (i, el; *oldelems)
{
(*newelems)[i] = copyLiteral(el ? el : basis).copy();
(*newelems)[i] = el ? copyLiteral(el).copy() : null;
}
return newelems;
}
Expand All @@ -226,9 +227,10 @@ UnionExp copyLiteral(Expression e)
}
if (auto ale = e.isArrayLiteralExp())
{
auto elements = copyLiteralArray(ale.elements, ale.basis);
auto elements = copyLiteralArray(ale.elements);
auto basis = ale.basis ? copyLiteral(ale.basis).copy() : null;

emplaceExp!(ArrayLiteralExp)(&ue, e.loc, e.type, elements);
emplaceExp!(ArrayLiteralExp)(&ue, e.loc, e.type, basis, elements);

ArrayLiteralExp r = ue.exp().isArrayLiteralExp();
r.ownedByCtfe = OwnedBy.ctfe;
Expand Down
Loading