diff mbox

Go patch committed: Error if no-value return with no result names

Message ID mcr8vw0fo2i.fsf@google.com
State New
Headers show

Commit Message

Ian Lance Taylor March 27, 2011, 5:52 p.m. UTC
This patch makes the gccgo frontend give an error if a return statement
with no values is used in a function with results for which the result
parameters have no names.  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline.

Ian
diff mbox

Patch

diff -r 015f1f9a7958 go/statements.cc
--- a/go/statements.cc	Sat Mar 26 22:34:39 2011 -0700
+++ b/go/statements.cc	Sun Mar 27 10:48:22 2011 -0700
@@ -2581,10 +2581,20 @@ 
 void
 Return_statement::do_check_types(Gogo*)
 {
+  const Typed_identifier_list* results = this->results_;
   if (this->vals_ == NULL)
-    return;
-
-  const Typed_identifier_list* results = this->results_;
+    {
+      if (results != NULL
+	  && !results->empty()
+	  && results->front().name().empty())
+	{
+	  // The result parameters are not named, which means that we
+	  // need to supply values for them.
+	  this->report_error(_("not enough arguments to return"));
+	}
+      return;
+    }
+
   if (results == NULL)
     {
       this->report_error(_("return with value in function "
@@ -2621,7 +2631,7 @@ 
     }
 
   if (pt != results->end())
-    this->report_error(_("not enough values in return statement"));
+    this->report_error(_("not enough arguments to return"));
 }
 
 // Build a RETURN_EXPR tree.