diff options
author | Ian Lance Taylor <iant@golang.org> | 2020-11-26 13:15:41 -0800 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2020-11-28 06:57:06 -0800 |
commit | 822ea13e499db20af2080b48fc3bb530e429bb8d (patch) | |
tree | 27de8915521c00ca7e6e1c48f251c505bad4d653 /gcc/go | |
parent | c04bd12b06a21ad4a9c432c109ec2a543725ad1b (diff) | |
download | gcc-822ea13e499db20af2080b48fc3bb530e429bb8d.zip gcc-822ea13e499db20af2080b48fc3bb530e429bb8d.tar.gz gcc-822ea13e499db20af2080b48fc3bb530e429bb8d.tar.bz2 |
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 :=
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/273546
Diffstat (limited to 'gcc/go')
-rw-r--r-- | gcc/go/gofrontend/MERGE | 2 | ||||
-rw-r--r-- | gcc/go/gofrontend/parse.cc | 14 |
2 files changed, 12 insertions, 4 deletions
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index c14ee7e..5964832 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -8cbe18aff99dbf79bd1adb9c025418e84505ffd5 +66669bb6cae475eda6666a94f6ff4f616ffa77d7 The first line of this file holds the git revision number of the last merge done from the gofrontend repository. diff --git a/gcc/go/gofrontend/parse.cc b/gcc/go/gofrontend/parse.cc index ef59415..aa157e8 100644 --- a/gcc/go/gofrontend/parse.cc +++ b/gcc/go/gofrontend/parse.cc @@ -2165,8 +2165,12 @@ Parse::simple_var_decl_or_assignment(const std::string& name, 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 @@ Parse::simple_var_decl_or_assignment(const std::string& name, 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)) { |