compiler: fix check for duplicate declaration
authorIan Lance Taylor <ian@gcc.gnu.org>
Fri, 22 Jul 2016 00:21:51 +0000 (00:21 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Fri, 22 Jul 2016 00:21:51 +0000 (00:21 +0000)
    The compiler check that issued a duplicate declaration error for
        a, a, a := 1, 2, 3
    was incorrectly issuing an error for
        a, a, a = 1, 2, 3
    While this is not particularly useful, it is valid Go.

    Test is https://golang.org/cl/25143.

    Reviewed-on: https://go-review.googlesource.com/25144

From-SVN: r238618

gcc/go/gofrontend/MERGE
gcc/go/gofrontend/parse.cc

index 7798423..7e8d9d4 100644 (file)
@@ -1,4 +1,4 @@
-5ea5c078829ae83bccb598772fff7c1a04e23e65
+4c88f31a83ca28963d29d6dc9fcdb2e9b093610c
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
index c96ae1d..d9f2040 100644 (file)
@@ -2106,6 +2106,8 @@ Parse::simple_var_decl_or_assignment(const std::string& name,
 
   std::set<std::string> uniq_idents;
   uniq_idents.insert(name);
+  std::string dup_name;
+  Location dup_loc;
 
   // We've seen one identifier.  If we see a comma now, this could be
   // "a, *p = 1, 2".
@@ -2145,8 +2147,10 @@ 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))
-           error_at(id_location, "multiple assignments to %s",
-                    Gogo::message_name(id).c_str());
+           {
+             dup_name = Gogo::message_name(id);
+             dup_loc = id_location;
+           }
          til.push_back(Typed_identifier(id, NULL, location));
        }
 
@@ -2182,6 +2186,9 @@ Parse::simple_var_decl_or_assignment(const std::string& name,
   go_assert(this->peek_token()->is_op(OPERATOR_COLONEQ));
   const Token* token = this->advance_token();
 
+  if (!dup_name.empty())
+    error_at(dup_loc, "multiple assignments to %s", dup_name.c_str());
+
   if (p_range_clause != NULL && token->is_keyword(KEYWORD_RANGE))
     {
       this->range_clause_decl(&til, p_range_clause);