diff --git a/expr.cpp b/expr.cpp index e928f15b..0db4b5f1 100644 --- a/expr.cpp +++ b/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(lhsType) != NULL) { if (op == AddAssign || op == SubAssign) { diff --git a/tests_errors/lvalue-1.ispc b/tests_errors/lvalue-1.ispc new file mode 100644 index 00000000..ada9abf3 --- /dev/null +++ b/tests_errors/lvalue-1.ispc @@ -0,0 +1,8 @@ +// Left hand side of assignment statement can't be assigned to + +int foo() {return 2;} + +int bar() +{ + foo() = 2; +} diff --git a/tests_errors/lvalue-2.ispc b/tests_errors/lvalue-2.ispc new file mode 100644 index 00000000..93dab8d2 --- /dev/null +++ b/tests_errors/lvalue-2.ispc @@ -0,0 +1,6 @@ +// Can't assign to type "const uniform int32" on left-hand side + +int bar(){ + 4 = 0; +} + diff --git a/tests_errors/lvalue-3.ispc b/tests_errors/lvalue-3.ispc new file mode 100644 index 00000000..f4fb830d --- /dev/null +++ b/tests_errors/lvalue-3.ispc @@ -0,0 +1,7 @@ +// Left hand side of assignment statement can't be assigned to + +int bar(){ + int x; + 4 = x; +} +