Commit 4114e6b1 by Ian Lance Taylor

compiler: fix check for duplicate declaration

    
    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
parent a94aa329
5ea5c078829ae83bccb598772fff7c1a04e23e65 4c88f31a83ca28963d29d6dc9fcdb2e9b093610c
The first line of this file holds the git revision number of the last The first line of this file holds the git revision number of the last
merge done from the gofrontend repository. merge done from the gofrontend repository.
...@@ -2106,6 +2106,8 @@ Parse::simple_var_decl_or_assignment(const std::string& name, ...@@ -2106,6 +2106,8 @@ Parse::simple_var_decl_or_assignment(const std::string& name,
std::set<std::string> uniq_idents; std::set<std::string> uniq_idents;
uniq_idents.insert(name); 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 // We've seen one identifier. If we see a comma now, this could be
// "a, *p = 1, 2". // "a, *p = 1, 2".
...@@ -2145,8 +2147,10 @@ Parse::simple_var_decl_or_assignment(const std::string& name, ...@@ -2145,8 +2147,10 @@ Parse::simple_var_decl_or_assignment(const std::string& name,
id = this->gogo_->pack_hidden_name(id, is_id_exported); id = this->gogo_->pack_hidden_name(id, is_id_exported);
ins = uniq_idents.insert(id); ins = uniq_idents.insert(id);
if (!ins.second && !Gogo::is_sink_name(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)); til.push_back(Typed_identifier(id, NULL, location));
} }
...@@ -2182,6 +2186,9 @@ Parse::simple_var_decl_or_assignment(const std::string& name, ...@@ -2182,6 +2186,9 @@ Parse::simple_var_decl_or_assignment(const std::string& name,
go_assert(this->peek_token()->is_op(OPERATOR_COLONEQ)); go_assert(this->peek_token()->is_op(OPERATOR_COLONEQ));
const Token* token = this->advance_token(); 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)) if (p_range_clause != NULL && token->is_keyword(KEYWORD_RANGE))
{ {
this->range_clause_decl(&til, p_range_clause); this->range_clause_decl(&til, p_range_clause);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment