From 3c6913212806e73738e8d26d44ac92c26f70287b Mon Sep 17 00:00:00 2001 From: RazvanN7 Date: Wed, 8 Feb 2023 16:14:12 +0200 Subject: [PATCH] Fix Issue 23674 - incompatible types for array comparison: string and string --- compiler/src/dmd/expressionsem.d | 9 +++++++++ compiler/test/fail_compilation/test23674.d | 15 +++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 compiler/test/fail_compilation/test23674.d 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]); +}