Issue error if any complex assignment operator is used with a struct type.
Issue #275.
This commit is contained in:
14
expr.cpp
14
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<StructType>(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;
|
||||
}
|
||||
|
||||
8
tests_errors/struct_arith.ispc
Normal file
8
tests_errors/struct_arith.ispc
Normal file
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user