compiler: Make sure we produce an error for a call to a non-function.
authorIan Lance Taylor <ian@gcc.gnu.org>
Wed, 5 Dec 2012 00:53:44 +0000 (00:53 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Wed, 5 Dec 2012 00:53:44 +0000 (00:53 +0000)
Fixes issue 19.

From-SVN: r194174

gcc/go/gofrontend/expressions.cc

index 3734d9b0b235eb1e9d1f782366a0f5542f3d7850..9da9414c3a69a81e12aca35ec486ee89a60a723f 100644 (file)
@@ -8544,6 +8544,16 @@ Call_expression::do_lower(Gogo* gogo, Named_object* function,
     return Expression::make_cast(this->fn_->type(), this->args_->front(),
                                 loc);
 
+  // Because do_type will return an error type and thus prevent future
+  // errors, check for that case now to ensure that the error gets
+  // reported.
+  if (this->get_function_type() == NULL)
+    {
+      if (!this->fn_->type()->is_error())
+       this->report_error(_("expected function"));
+      return Expression::make_error(loc);
+    }
+
   // Recognize a call to a builtin function.
   Func_expression* fne = this->fn_->func_expression();
   if (fne != NULL