Do assignment lvalue error checking in type checking
Added some tests related to this. Also improved source file position reporting in error reporting.
This commit is contained in:
14
expr.cpp
14
expr.cpp
@@ -2037,12 +2037,8 @@ AssignExpr::GetValue(FunctionEmitContext *ctx) const {
|
||||
ctx->SetDebugPos(pos);
|
||||
|
||||
Symbol *baseSym = lvalue->GetBaseSymbol();
|
||||
if (!baseSym) {
|
||||
// FIXME: I think that this check also is unnecessary and that this
|
||||
// case should be covered during type checking.
|
||||
Error(pos, "Left hand side of assignment statement can't be assigned to.");
|
||||
return NULL;
|
||||
}
|
||||
// Should be caught during type-checking...
|
||||
assert(baseSym != NULL);
|
||||
|
||||
switch (op) {
|
||||
case Assign: {
|
||||
@@ -2180,6 +2176,12 @@ AssignExpr::TypeCheck() {
|
||||
}
|
||||
}
|
||||
|
||||
if (lvalue->GetBaseSymbol() == NULL) {
|
||||
Error(lvalue->pos, "Left hand side of assignment statement can't be "
|
||||
"assigned to.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const Type *lhsType = lvalue->GetType();
|
||||
if (dynamic_cast<const PointerType *>(lhsType) != NULL) {
|
||||
if (op == AddAssign || op == SubAssign) {
|
||||
|
||||
Reference in New Issue
Block a user