diff --git a/expr.cpp b/expr.cpp index 7c270f46..cc03ba20 100644 --- a/expr.cpp +++ b/expr.cpp @@ -2892,10 +2892,18 @@ AssignExpr::TypeCheck() { return NULL; } - // Make sure we're not assigning to a struct that has a constant member const StructType *st = CastType(lhsType); - if (st != NULL && lCheckForConstStructMember(pos, st, st)) - return NULL; + if (st != NULL) { + // Make sure we're not assigning to a struct that has a constant member + if (lCheckForConstStructMember(pos, st, st)) + return NULL; + + if (op != Assign) { + Error(lvalue->pos, "Assignment operator \"%s\" is illegal with struct " + "type \"%s\".", lOpString(op), st->GetString().c_str()); + return NULL; + } + } return this; } diff --git a/tests_errors/struct_arith.ispc b/tests_errors/struct_arith.ispc new file mode 100644 index 00000000..9d942880 --- /dev/null +++ b/tests_errors/struct_arith.ispc @@ -0,0 +1,8 @@ +// Assignment operator "+=" is illegal with struct type + +struct Point { float x, y, z; }; + +void foo() { + Point a = {1,2,3}, b = {4,5,6}; + a += b; +}