This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Go patch committed: Better error message for type switch
- From: Ian Lance Taylor <iant at google dot com>
- To: gcc-patches at gcc dot gnu dot org, gofrontend-dev at googlegroups dot com
- Date: Mon, 28 Mar 2011 16:19:02 -0700
- Subject: Go patch committed: Better error message for type switch
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 -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 %<{%>");