Skip to content

Commit

Permalink
fix Issue 12985 - Better error message for not supported array operation
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Oct 5, 2014
1 parent 2efa27a commit 2ae8fe4
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 41 deletions.
7 changes: 5 additions & 2 deletions src/arrayop.c
Expand Up @@ -154,11 +154,14 @@ bool isNonAssignmentArrayOp(Expression *e)
return false;
}

bool checkNonAssignmentArrayOp(Expression *e)
bool checkNonAssignmentArrayOp(Expression *e, bool suggestion)
{
if (isNonAssignmentArrayOp(e))
{
e->error("array operation %s without assignment not implemented", e->toChars());
const char *s = "";
if (suggestion)
s = " (did you forget a [] ?)";
e->error("array operation %s without destination memory not allowed%s", e->toChars(), s);
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/expression.c
Expand Up @@ -11514,7 +11514,7 @@ Expression *AssignExp::semantic(Scope *sc)

// Drop invalid array operations in e2
// d = a[] + b[], d = (a[] + b[])[0..2], etc
if (checkNonAssignmentArrayOp(e2))
if (checkNonAssignmentArrayOp(e2, !ismemset && op == TOKassign))
return new ErrorExp();

// Remains valid array assignments
Expand Down
2 changes: 1 addition & 1 deletion src/expression.h
Expand Up @@ -80,7 +80,7 @@ int isConst(Expression *e);
Expression *toDelegate(Expression *e, Scope *sc);
AggregateDeclaration *isAggregate(Type *t);
IntRange getIntRange(Expression *e);
bool checkNonAssignmentArrayOp(Expression *e);
bool checkNonAssignmentArrayOp(Expression *e, bool suggestion = false);
bool isUnaArrayOp(TOK op);
bool isBinArrayOp(TOK op);
bool isBinAssignArrayOp(TOK op);
Expand Down
22 changes: 11 additions & 11 deletions test/fail_compilation/fail9459.d
Expand Up @@ -3,17 +3,17 @@ REQUIRED_ARGS: -o-
PERMUTE_ARGS:
TEST_OUTPUT:
---
fail_compilation/fail9459.d(32): Error: array operation -a[] without assignment not implemented
fail_compilation/fail9459.d(33): Error: array operation ~a[] without assignment not implemented
fail_compilation/fail9459.d(35): Error: array operation a[] + a[] without assignment not implemented
fail_compilation/fail9459.d(36): Error: array operation a[] - a[] without assignment not implemented
fail_compilation/fail9459.d(37): Error: array operation a[] * a[] without assignment not implemented
fail_compilation/fail9459.d(38): Error: array operation a[] / a[] without assignment not implemented
fail_compilation/fail9459.d(39): Error: array operation a[] % a[] without assignment not implemented
fail_compilation/fail9459.d(40): Error: array operation a[] ^ a[] without assignment not implemented
fail_compilation/fail9459.d(41): Error: array operation a[] & a[] without assignment not implemented
fail_compilation/fail9459.d(42): Error: array operation a[] | a[] without assignment not implemented
fail_compilation/fail9459.d(43): Error: array operation a[] ^^ a[] without assignment not implemented
fail_compilation/fail9459.d(32): Error: array operation -a[] without destination memory not allowed (did you forget a [] ?)
fail_compilation/fail9459.d(33): Error: array operation ~a[] without destination memory not allowed (did you forget a [] ?)
fail_compilation/fail9459.d(35): Error: array operation a[] + a[] without destination memory not allowed (did you forget a [] ?)
fail_compilation/fail9459.d(36): Error: array operation a[] - a[] without destination memory not allowed (did you forget a [] ?)
fail_compilation/fail9459.d(37): Error: array operation a[] * a[] without destination memory not allowed (did you forget a [] ?)
fail_compilation/fail9459.d(38): Error: array operation a[] / a[] without destination memory not allowed (did you forget a [] ?)
fail_compilation/fail9459.d(39): Error: array operation a[] % a[] without destination memory not allowed (did you forget a [] ?)
fail_compilation/fail9459.d(40): Error: array operation a[] ^ a[] without destination memory not allowed (did you forget a [] ?)
fail_compilation/fail9459.d(41): Error: array operation a[] & a[] without destination memory not allowed (did you forget a [] ?)
fail_compilation/fail9459.d(42): Error: array operation a[] | a[] without destination memory not allowed (did you forget a [] ?)
fail_compilation/fail9459.d(43): Error: array operation a[] ^^ a[] without destination memory not allowed (did you forget a [] ?)
fail_compilation/fail9459.d(45): Error: invalid array operation a += a[] (did you forget a [] ?)
fail_compilation/fail9459.d(46): Error: invalid array operation a -= a[] (did you forget a [] ?)
fail_compilation/fail9459.d(47): Error: invalid array operation a *= a[] (did you forget a [] ?)
Expand Down
40 changes: 20 additions & 20 deletions test/fail_compilation/ice12179.d
@@ -1,19 +1,19 @@
/*
TEST_OUTPUT:
---
fail_compilation/ice12179.d(25): Error: array operation a[] + a[] without assignment not implemented
fail_compilation/ice12179.d(26): Error: array operation a[] - a[] without assignment not implemented
fail_compilation/ice12179.d(27): Error: array operation a[] * a[] without assignment not implemented
fail_compilation/ice12179.d(28): Error: array operation a[] / a[] without assignment not implemented
fail_compilation/ice12179.d(29): Error: array operation a[] % a[] without assignment not implemented
fail_compilation/ice12179.d(30): Error: array operation a[] ^ a[] without assignment not implemented
fail_compilation/ice12179.d(31): Error: array operation a[] & a[] without assignment not implemented
fail_compilation/ice12179.d(32): Error: array operation a[] | a[] without assignment not implemented
fail_compilation/ice12179.d(33): Error: array operation a[] ^^ 10 without assignment not implemented
fail_compilation/ice12179.d(34): Error: array operation -a[] without assignment not implemented
fail_compilation/ice12179.d(35): Error: array operation ~a[] without assignment not implemented
fail_compilation/ice12179.d(40): Error: array operation [1] + a[] without assignment not implemented
fail_compilation/ice12179.d(41): Error: array operation [1] + a[] without assignment not implemented
fail_compilation/ice12179.d(25): Error: array operation a[] + a[] without destination memory not allowed
fail_compilation/ice12179.d(26): Error: array operation a[] - a[] without destination memory not allowed
fail_compilation/ice12179.d(27): Error: array operation a[] * a[] without destination memory not allowed
fail_compilation/ice12179.d(28): Error: array operation a[] / a[] without destination memory not allowed
fail_compilation/ice12179.d(29): Error: array operation a[] % a[] without destination memory not allowed
fail_compilation/ice12179.d(30): Error: array operation a[] ^ a[] without destination memory not allowed
fail_compilation/ice12179.d(31): Error: array operation a[] & a[] without destination memory not allowed
fail_compilation/ice12179.d(32): Error: array operation a[] | a[] without destination memory not allowed
fail_compilation/ice12179.d(33): Error: array operation a[] ^^ 10 without destination memory not allowed
fail_compilation/ice12179.d(34): Error: array operation -a[] without destination memory not allowed
fail_compilation/ice12179.d(35): Error: array operation ~a[] without destination memory not allowed
fail_compilation/ice12179.d(40): Error: array operation [1] + a[] without destination memory not allowed
fail_compilation/ice12179.d(41): Error: array operation [1] + a[] without destination memory not allowed
---
*/

Expand Down Expand Up @@ -45,8 +45,8 @@ void main()
/*
TEST_OUTPUT:
---
fail_compilation/ice12179.d(55): Error: array operation -a[] without assignment not implemented
fail_compilation/ice12179.d(57): Error: array operation (-a[])[0..4] without assignment not implemented
fail_compilation/ice12179.d(55): Error: array operation -a[] without destination memory not allowed
fail_compilation/ice12179.d(57): Error: array operation (-a[])[0..4] without destination memory not allowed
---
*/
float[] f12769(float[] a)
Expand All @@ -60,11 +60,11 @@ float[] f12769(float[] a)
/*
TEST_OUTPUT:
---
fail_compilation/ice12179.d(74): Error: array operation a[] - a[] without assignment not implemented
fail_compilation/ice12179.d(76): Error: array operation a[] - a[] without assignment not implemented
fail_compilation/ice12179.d(77): Error: array operation a[] - a[] without assignment not implemented
fail_compilation/ice12179.d(80): Error: array operation a[] - a[] without assignment not implemented
fail_compilation/ice12179.d(82): Error: array operation a[] - a[] without assignment not implemented
fail_compilation/ice12179.d(74): Error: array operation a[] - a[] without destination memory not allowed
fail_compilation/ice12179.d(76): Error: array operation a[] - a[] without destination memory not allowed
fail_compilation/ice12179.d(77): Error: array operation a[] - a[] without destination memory not allowed
fail_compilation/ice12179.d(80): Error: array operation a[] - a[] without destination memory not allowed
fail_compilation/ice12179.d(82): Error: array operation a[] - a[] without destination memory not allowed
---
*/
void test13208()
Expand Down
10 changes: 5 additions & 5 deletions test/fail_compilation/ice13497.d
Expand Up @@ -2,10 +2,10 @@
/*
TEST_OUTPUT:
---
fail_compilation/ice13497.d(15): Error: array operation a[] * a[] without assignment not implemented
fail_compilation/ice13497.d(16): Error: array operation (a[] * a[])[0..1] without assignment not implemented
fail_compilation/ice13497.d(19): Error: array operation a[] * a[] without assignment not implemented
fail_compilation/ice13497.d(20): Error: array operation (a[] * a[])[0..1] without assignment not implemented
fail_compilation/ice13497.d(15): Error: array operation a[] * a[] without destination memory not allowed
fail_compilation/ice13497.d(16): Error: array operation (a[] * a[])[0..1] without destination memory not allowed
fail_compilation/ice13497.d(19): Error: array operation a[] * a[] without destination memory not allowed (did you forget a [] ?)
fail_compilation/ice13497.d(20): Error: array operation (a[] * a[])[0..1] without destination memory not allowed (did you forget a [] ?)
---
*/

Expand All @@ -23,7 +23,7 @@ void test13497()
/*
TEST_OUTPUT:
---
fail_compilation/ice13497.d(34): Error: array operation h * y[] without assignment not implemented
fail_compilation/ice13497.d(34): Error: array operation h * y[] without destination memory not allowed
---
*/
void test12381()
Expand Down
2 changes: 1 addition & 1 deletion test/fail_compilation/ice2603.d
@@ -1,7 +1,7 @@
/*
TEST_OUTPUT:
---
fail_compilation/ice2603.d(17): Error: array operation [1, 2, 3] - [1, 2, 3] without assignment not implemented
fail_compilation/ice2603.d(17): Error: array operation [1, 2, 3] - [1, 2, 3] without destination memory not allowed
fail_compilation/ice2603.d(20): Error: invalid array operation "a" - "b" (did you forget a [] ?)
---
*/
Expand Down

0 comments on commit 2ae8fe4

Please sign in to comment.