diff --git a/compiler/src/dmd/expressionsem.d b/compiler/src/dmd/expressionsem.d index ea83871d4697..9ae3940fe2d8 100644 --- a/compiler/src/dmd/expressionsem.d +++ b/compiler/src/dmd/expressionsem.d @@ -12042,6 +12042,15 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor __equals = new DotIdExp(exp.loc, __equals, Id.object); __equals = new DotIdExp(exp.loc, __equals, id); + /* https://issues.dlang.org/show_bug.cgi?id=23674 + * + * Optimize before creating the call expression to the + * druntime hook as the optimizer may output errors + * that will get swallowed otherwise. + */ + exp.e1 = exp.e1.optimize(WANTvalue); + exp.e2 = exp.e2.optimize(WANTvalue); + auto arguments = new Expressions(2); (*arguments)[0] = exp.e1; (*arguments)[1] = exp.e2; diff --git a/compiler/test/fail_compilation/test23674.d b/compiler/test/fail_compilation/test23674.d new file mode 100644 index 000000000000..0f11de94d9da --- /dev/null +++ b/compiler/test/fail_compilation/test23674.d @@ -0,0 +1,15 @@ +// https://issues.dlang.org/show_bug.cgi?id=23674 + +/* +TEST_OUTPUT: +--- +fail_compilation/test23674.d(14): Error: array index 2 is out of bounds `arr[0 .. 2]` +fail_compilation/test23674.d(14): Error: array index 3 is out of bounds `arr[0 .. 2]` +--- +*/ + +void main() +{ + string[2] arr; + assert(arr[2] == arr[3]); +}