Better error messages for missing channel element type.
authorIan Lance Taylor <ian@gcc.gnu.org>
Mon, 28 Mar 2011 21:50:53 +0000 (21:50 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Mon, 28 Mar 2011 21:50:53 +0000 (21:50 +0000)
From-SVN: r171634

gcc/go/gofrontend/parse.cc

index 76dd9d04e435d024f3abfdba36313550a5333b3d..3f783b127c10cce43919881139f6830765c9a7ec 100644 (file)
@@ -656,6 +656,23 @@ Parse::channel_type()
          this->advance_token();
        }
     }
+
+  // Better error messages for the common error of omitting the
+  // channel element type.
+  if (!this->type_may_start_here())
+    {
+      token = this->peek_token();
+      if (token->is_op(OPERATOR_RCURLY))
+       error_at(this->location(), "unexpected %<}%> in channel type");
+      else if (token->is_op(OPERATOR_RPAREN))
+       error_at(this->location(), "unexpected %<)%> in channel type");
+      else if (token->is_op(OPERATOR_COMMA))
+       error_at(this->location(), "unexpected comma in channel type");
+      else
+       error_at(this->location(), "expected channel element type");
+      return Type::make_error_type();
+    }
+
   Type* element_type = this->type();
   return Type::make_channel_type(send, receive, element_type);
 }