aboutsummaryrefslogtreecommitdiff
path: root/gcc/go/gofrontend/parse.cc
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2020-01-09 15:58:42 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2020-01-09 15:58:42 +0000
commit0581e6ba3cfeb646553574aaa0efb1a822550a1f (patch)
treefa419773d258339a511cb550a8739b57ca49d154 /gcc/go/gofrontend/parse.cc
parentd6491d15676b0255eaaa4f5394fbb8ec7e3c6a5f (diff)
downloadgcc-0581e6ba3cfeb646553574aaa0efb1a822550a1f.zip
gcc-0581e6ba3cfeb646553574aaa0efb1a822550a1f.tar.gz
gcc-0581e6ba3cfeb646553574aaa0efb1a822550a1f.tar.bz2
compiler: don't add composite literal keys to package bindings
Adding composite literal keys to package bindings gets confusing when it is combined with dot imports. The test case showing the resulting compilation failure is https://golang.org/cl/213899. Fix this by adding a new expression type to hold composite literal keys. We shouldn't see it during lowering if it is a struct field name, because Composite_literal_expression::do_traverse skips struct field names. Or, it should, but that didn't quite work with pointer types so it had to be tweaked. This lets us remove the code that recorded whether an Unknown_expression is a composite literal key. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/214017 From-SVN: r280056
Diffstat (limited to 'gcc/go/gofrontend/parse.cc')
-rw-r--r--gcc/go/gofrontend/parse.cc23
1 files changed, 15 insertions, 8 deletions
diff --git a/gcc/go/gofrontend/parse.cc b/gcc/go/gofrontend/parse.cc
index e50af61..084cdbf 100644
--- a/gcc/go/gofrontend/parse.cc
+++ b/gcc/go/gofrontend/parse.cc
@@ -2200,7 +2200,7 @@ Parse::simple_var_decl_or_assignment(const std::string& name,
p != til.end();
++p)
exprs->push_back(this->id_to_expression(p->name(), p->location(),
- true));
+ true, false));
Expression_list* more_exprs =
this->expression_list(NULL, true, may_be_composite_lit);
@@ -2820,7 +2820,7 @@ Parse::composite_lit(Type* type, int depth, Location location)
Gogo* gogo = this->gogo_;
val = this->id_to_expression(gogo->pack_hidden_name(identifier,
is_exported),
- id_location, false);
+ id_location, false, true);
is_name = true;
}
else
@@ -2877,9 +2877,6 @@ Parse::composite_lit(Type* type, int depth, Location location)
}
has_keys = true;
- if (val->unknown_expression() != NULL)
- val->unknown_expression()->set_is_composite_literal_key();
-
vals->push_back(val);
if (!token->is_op(OPERATOR_LCURLY))
@@ -3345,12 +3342,22 @@ Parse::call(Expression* func)
Expression*
Parse::id_to_expression(const std::string& name, Location location,
- bool is_lhs)
+ bool is_lhs, bool is_composite_literal_key)
{
Named_object* in_function;
Named_object* named_object = this->gogo_->lookup(name, &in_function);
if (named_object == NULL)
- named_object = this->gogo_->add_unknown_name(name, location);
+ {
+ if (is_composite_literal_key)
+ {
+ // This is a composite literal key, which means that it
+ // could just be a struct field name, so avoid confusiong by
+ // not adding it to the bindings. We'll look up the name
+ // later during the lowering phase if necessary.
+ return Expression::make_composite_literal_key(name, location);
+ }
+ named_object = this->gogo_->add_unknown_name(name, location);
+ }
if (in_function != NULL
&& in_function != this->gogo_->current_function()
@@ -5167,7 +5174,7 @@ Parse::send_or_recv_stmt(bool* is_send, Expression** channel, Expression** val,
*val = this->id_to_expression(gogo->pack_hidden_name(recv_var,
is_rv_exported),
- recv_var_loc, true);
+ recv_var_loc, true, false);
saw_comma = true;
}
else