diff mbox

Go patch committed: Better error message for type switch

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

Commit Message

Ian Lance Taylor March 28, 2011, 11:19 p.m. UTC
This patch to the Go frontend generates a better error message when an
invalid variable name is used in a switch statement.  Bootstrapped and
ran Go testsuite on x86_64-unknown-linux-gnu.  Committed to mainline.

Ian
diff mbox

Patch

diff -r 9f4bdd962616 go/parse.cc
--- a/go/parse.cc	Mon Mar 28 15:57:46 2011 -0700
+++ b/go/parse.cc	Mon Mar 28 16:09:10 2011 -0700
@@ -3919,6 +3919,19 @@ 
       if (this->peek_token()->is_op(OPERATOR_SEMICOLON)
 	  && this->advance_token()->is_op(OPERATOR_LCURLY))
 	error_at(token_loc, "unexpected semicolon or newline before %<{%>");
+      else if (this->peek_token()->is_op(OPERATOR_COLONEQ))
+	{
+	  error_at(token_loc, "invalid variable name");
+	  this->advance_token();
+	  this->expression(PRECEDENCE_NORMAL, false, false,
+			   &type_switch.found);
+	  if (this->peek_token()->is_op(OPERATOR_SEMICOLON))
+	    this->advance_token();
+	  if (!this->peek_token()->is_op(OPERATOR_LCURLY))
+	    return;
+	  if (type_switch.found)
+	    type_switch.expr = Expression::make_error(location);
+	}
       else
 	{
 	  error_at(this->location(), "expected %<{%>");