Fix Issue 21699 - Issue 21699 - Duplicate error for index out of bounds at compile time

This commit is contained in:
RazvanN7 2021-03-11 11:26:01 +02:00 committed by The Dlang Bot
parent 894db5434c
commit 36e80656e7
2 changed files with 5 additions and 9 deletions

View file

@ -1012,7 +1012,7 @@ Expression Expression_optimize(Expression e, int result, bool keepLvalue)
if (keepLvalue && ex.op == TOK.arrayLiteral)
return;
ret = Index(e.type, ex, e.e2).copy();
if (CTFEExp.isCantExp(ret) || (keepLvalue && !ret.isLvalue()))
if (CTFEExp.isCantExp(ret) || (!ret.isErrorExp() && keepLvalue && !ret.isLvalue()))
ret = e;
}

View file

@ -1,14 +1,10 @@
/*
TEST_OUTPUT:
---
fail_compilation/test6883.d(19): Error: array index 5 is out of bounds `x[0 .. 5]`
fail_compilation/test6883.d(19): Error: array index 5 is out of bounds `x[0 .. 5]`
fail_compilation/test6883.d(21): Error: array index 7 is out of bounds `x[0 .. 5]`
fail_compilation/test6883.d(21): Error: array index 7 is out of bounds `x[0 .. 5]`
fail_compilation/test6883.d(25): Error: array index 5 is out of bounds `x[0 .. 5]`
fail_compilation/test6883.d(25): Error: array index 5 is out of bounds `x[0 .. 5]`
fail_compilation/test6883.d(27): Error: array index 7 is out of bounds `x[0 .. 5]`
fail_compilation/test6883.d(27): Error: array index 7 is out of bounds `x[0 .. 5]`
fail_compilation/test6883.d(15): Error: array index 5 is out of bounds `x[0 .. 5]`
fail_compilation/test6883.d(17): Error: array index 7 is out of bounds `x[0 .. 5]`
fail_compilation/test6883.d(21): Error: array index 5 is out of bounds `x[0 .. 5]`
fail_compilation/test6883.d(23): Error: array index 7 is out of bounds `x[0 .. 5]`
---
*/