From patchwork Thu Sep 2 00:08:21 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [gccgo] Better message for use of [...] outside of array literal From: Ian Taylor X-Patchwork-Id: 63428 Message-Id: To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Date: Wed, 01 Sep 2010 17:08:21 -0700 This patch to gccgo gives a better message for an erronsous use of [...] outside of an array literal. Committed to gccgo branch. Ian 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; }