diff mbox

[gccgo] Better message for use of [...] outside of array literal

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

Commit Message

Ian Lance Taylor Sept. 2, 2010, 12:08 a.m. UTC
This patch to gccgo gives a better message for an erronsous use of [...]
outside of an array literal.  Committed to gccgo branch.

Ian
diff mbox

Patch

diff -r 68086824a127 go/parse.cc
--- a/go/parse.cc	Wed Sep 01 16:53:16 2010 -0700
+++ b/go/parse.cc	Wed Sep 01 17:05:42 2010 -0700
@@ -375,9 +375,9 @@ 
     this->advance_token();
   else
     {
-      if (!may_use_ellipsis || !token->is_op(OPERATOR_ELLIPSIS))
+      if (!token->is_op(OPERATOR_ELLIPSIS))
 	length = this->expression(PRECEDENCE_NORMAL, false, true, NULL);
-      else
+      else if (may_use_ellipsis)
 	{
 	  // An ellipsis is used in composite literals to represent a
 	  // fixed array of the size of the number of elements.  We
@@ -386,6 +386,12 @@ 
 	  length = Expression::make_nil(this->location());
 	  this->advance_token();
 	}
+      else
+	{
+	  this->error("use of %<[...]%> outside of array literal");
+	  length = Expression::make_error(this->location());
+	  this->advance_token();
+	}
       if (!this->peek_token()->is_op(OPERATOR_RSQUARE))
 	{
 	  this->error("expected %<]%>");
diff -r 68086824a127 go/types.cc
--- a/go/types.cc	Wed Sep 01 16:53:16 2010 -0700
+++ b/go/types.cc	Wed Sep 01 17:05:42 2010 -0700
@@ -3418,7 +3418,8 @@ 
     }
   else
     {
-      error_at(this->length_->location(), "array bound is not numeric");
+      if (!t->is_error_type())
+	error_at(this->length_->location(), "array bound is not numeric");
       return false;
     }