Skip to content

Commit

Permalink
add error message for Issue 11717 - CTFE: [ICE] non-constant value wi…
Browse files Browse the repository at this point in the history
…th array and vector ops
  • Loading branch information
WalterBright committed Apr 25, 2016
1 parent bbbc12b commit f571e8a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
34 changes: 20 additions & 14 deletions src/dinterpret.d
Original file line number Diff line number Diff line change
Expand Up @@ -3215,25 +3215,31 @@ public:
return;
}

Expression e1 = interpret(e.e1, istate);
if (exceptionOrCant(e1))
return;
if (e1.isConst() != 1)
bool evalOperand(Expression ex, out Expression er)
{
e.error("CTFE internal error: non-constant value %s", e.e1.toChars());
result = CTFEExp.cantexp;
return;
er = interpret(ex, istate);
if (exceptionOrCant(er))
return false;
if (er.isConst() != 1)
{
if (er.op == TOKarrayliteral)
// Until we get it to work, issue a reasonable error message
e.error("cannot interpret array literal expression %s at compile time", e.toChars());
else
e.error("CTFE internal error: non-constant value %s", ex.toChars());
result = CTFEExp.cantexp;
return false;
}
return true;
}

Expression e2 = interpret(e.e2, istate);
if (exceptionOrCant(e2))
Expression e1;
if (!evalOperand(e.e1, e1))
return;
if (e2.isConst() != 1)
{
e.error("CTFE internal error: non-constant value %s", e.e2.toChars());
result = CTFEExp.cantexp;

Expression e2;
if (!evalOperand(e.e2, e2))
return;
}

if (e.op == TOKshr || e.op == TOKshl || e.op == TOKushr)
{
Expand Down
14 changes: 14 additions & 0 deletions test/fail_compilation/fail11717.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
TEST_OUTPUT:
---
fail_compilation/fail11717.d(13): Error: cannot interpret array literal expression [1, 2, 3, 4] + [1, 2, 3, 4] at compile time
---
*/

// https://issues.dlang.org/show_bug.cgi?id=11717

enum int[4] A = [1,2,3,4];
enum int[4] B = [1,2,3,4];
// Internal Compiler Error: non-constant value [1, 2, 3, 4]
enum int[4] C = A[] + B[];

0 comments on commit f571e8a

Please sign in to comment.