diff mbox

Go patch committed: Error for invalid use of ...

Message ID mcr62cpy8pp.fsf@dhcp-172-18-216-180.mtv.corp.google.com
State New
Headers show

Commit Message

Ian Lance Taylor April 24, 2012, 5:55 a.m. UTC
This patch to the Go compiler issues error messages for some invalid
uses of ... in function calls.  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline and 4.7 branch.

Ian
diff mbox

Patch

diff -r a69e43eba4d7 go/expressions.cc
--- a/go/expressions.cc	Mon Apr 23 14:35:45 2012 -0700
+++ b/go/expressions.cc	Mon Apr 23 22:47:31 2012 -0700
@@ -8641,7 +8641,14 @@ 
 	new_args->push_back(*pa);
       else if (this->is_varargs_)
 	{
-	  this->report_error(_("too many arguments"));
+	  if ((*pa)->type()->is_slice_type())
+	    this->report_error(_("too many arguments"));
+	  else
+	    {
+	      error_at(this->location(),
+		       _("invalid use of %<...%> with non-slice"));
+	      this->set_is_error();
+	    }
 	  return;
 	}
       else
@@ -8886,6 +8893,9 @@ 
 void
 Call_expression::do_check_types(Gogo*)
 {
+  if (this->classification() == EXPRESSION_ERROR)
+    return;
+
   Function_type* fntype = this->get_function_type();
   if (fntype == NULL)
     {
@@ -8921,7 +8931,17 @@ 
     }
 
   // Note that varargs was handled by the lower_varargs() method, so
-  // we don't have to worry about it here.
+  // we don't have to worry about it here unless something is wrong.
+  if (this->is_varargs_ && !this->varargs_are_lowered_)
+    {
+      if (!fntype->is_varargs())
+	{
+	  error_at(this->location(),
+		   _("invalid use of %<...%> calling non-variadic function"));
+	  this->set_is_error();
+	  return;
+	}
+    }
 
   const Typed_identifier_list* parameters = fntype->parameters();
   if (this->args_ == NULL)