compiler: better error for x, x := 1, 2
Was
assign.go:59:28: error: multiple assignments to x
Now
assign.go:59:28: error: ‘x’ repeated on left side of :=
Change-Id: I4b69a96950a6077145822ef625fb2117424897f3
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/273546
Trust: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
diff --git a/go/parse.cc b/go/parse.cc
index ef59415..aa157e8 100644
--- a/go/parse.cc
+++ b/go/parse.cc
@@ -2165,8 +2165,12 @@
id = this->gogo_->pack_hidden_name(id, is_id_exported);
ins = uniq_idents.insert(id);
if (!ins.second && !Gogo::is_sink_name(id))
- go_error_at(id_location, "multiple assignments to %s",
- Gogo::message_name(id).c_str());
+ {
+ // Use %s to print := to avoid -Wformat-diag warning.
+ go_error_at(id_location,
+ "%qs repeated on left side of %s",
+ Gogo::message_name(id).c_str(), ":=");
+ }
til.push_back(Typed_identifier(id, NULL, location));
}
else
@@ -2219,7 +2223,11 @@
const Token* token = this->advance_token();
if (!dup_name.empty())
- go_error_at(dup_loc, "multiple assignments to %s", dup_name.c_str());
+ {
+ // Use %s to print := to avoid -Wformat-diag warning.
+ go_error_at(dup_loc, "%qs repeated on left side of %s",
+ dup_name.c_str(), ":=");
+ }
if (p_range_clause != NULL && token->is_keyword(KEYWORD_RANGE))
{