From f97417a3c200f5a1b4bfcf6fcd11f086a4416546 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Tue, 24 Mar 2026 18:00:22 +0000 Subject: [PATCH] Fix slicing struct init array field with `ArrayLiteralExpression.basis` set --- compiler/src/dmd/constfold.d | 2 +- compiler/test/compilable/test8717.d | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/compiler/src/dmd/constfold.d b/compiler/src/dmd/constfold.d index 1dc6c4ca2de3..2a43c8e27537 100644 --- a/compiler/src/dmd/constfold.d +++ b/compiler/src/dmd/constfold.d @@ -1267,7 +1267,7 @@ UnionExp Slice(Type type, Expression e1, Expression lwr, Expression upr) { auto elements = new Expressions(cast(size_t)(iupr - ilwr)); memcpy(elements.tdata(), es1.elements.tdata() + ilwr, cast(size_t)(iupr - ilwr) * ((*es1.elements)[0]).sizeof); - emplaceExp!(ArrayLiteralExp)(&ue, e1.loc, type, elements); + emplaceExp!(ArrayLiteralExp)(&ue, e1.loc, type, es1.basis, elements); } } else diff --git a/compiler/test/compilable/test8717.d b/compiler/test/compilable/test8717.d index 26a2866c682b..455d72c14cc1 100644 --- a/compiler/test/compilable/test8717.d +++ b/compiler/test/compilable/test8717.d @@ -60,4 +60,6 @@ static if(SPT.init.sii != 1) { static assert(0); } static if(SPT.sf() != 1) { static assert(0); } static if(SPT.init.f() != 1) { static assert(0); } -void main() { } +// https://github.com/dlang/dmd/issues/22699 +struct S{ int[8] e; } +static assert(S().e[0..4] == S.init.e[0..4]);