Better error message for invalid variable name in switch statement.
authorIan Lance Taylor <ian@gcc.gnu.org>
Mon, 28 Mar 2011 23:13:04 +0000 (23:13 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Mon, 28 Mar 2011 23:13:04 +0000 (23:13 +0000)
From-SVN: r171639

gcc/go/gofrontend/parse.cc

index c7cd1087b803b5dc5d6446f8e8e94e2d83417190..fb590195597a46e1d303ac469b9d2fa21b07198c 100644 (file)
@@ -3919,6 +3919,19 @@ Parse::switch_stat(Label* label)
       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 %<{%>");