diff --git a/expr.cpp b/expr.cpp index eb0567f5..4ee0b52e 100644 --- a/expr.cpp +++ b/expr.cpp @@ -6305,8 +6305,17 @@ DereferenceExpr::GetType() const { Expr * DereferenceExpr::TypeCheck() { - if (expr == NULL) + if (expr == NULL) { + Assert(m->errorCount > 0); return NULL; + } + + if (dynamic_cast(expr->GetType()) == NULL) { + Error(pos, "Illegal to dereference non-pointer type \"%s\".", + expr->GetType()->GetString().c_str()); + return NULL; + } + return this; } diff --git a/tests_errors/deref-4.ispc b/tests_errors/deref-4.ispc new file mode 100644 index 00000000..0c45083b --- /dev/null +++ b/tests_errors/deref-4.ispc @@ -0,0 +1,6 @@ +// Illegal to dereference non-pointer type "float" + +float func(float a) { + *a = 0; + return 0; +}