diff options
author | Ian Lance Taylor <iant@golang.org> | 2020-04-09 17:42:37 -0700 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2020-04-09 18:19:11 -0700 |
commit | d09f80ae014613edb0197b36d94242f83da75696 (patch) | |
tree | 944e48f5ccdc38f45b244820bae48df0006b86c2 /gcc/go | |
parent | fef3d8b4a072757a0a4970b3ce566c354de150d3 (diff) | |
download | gcc-d09f80ae014613edb0197b36d94242f83da75696.zip gcc-d09f80ae014613edb0197b36d94242f83da75696.tar.gz gcc-d09f80ae014613edb0197b36d94242f83da75696.tar.bz2 |
compiler: look up composite literal keys in the global namespace
A composite literal key may not have a global definition, so
Gogo::define_global_names may not see it. In order to correctly
handle the case in which a predeclared identifier is used as a
composite literal key, do an explicit check of the global namespace.
Test case is https://golang.org/cl/227783.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/227784
Diffstat (limited to 'gcc/go')
-rw-r--r-- | gcc/go/gofrontend/MERGE | 2 | ||||
-rw-r--r-- | gcc/go/gofrontend/expressions.cc | 14 |
2 files changed, 12 insertions, 4 deletions
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index c5e8b29..b3cc9ec 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -4a31d064fd6996f64b620104e849292af8f25e12 +b31fbf7d8f23508cfbd578c5c44b13eefd8f359e 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/expressions.cc b/gcc/go/gofrontend/expressions.cc index 42ad93b..deac874 100644 --- a/gcc/go/gofrontend/expressions.cc +++ b/gcc/go/gofrontend/expressions.cc @@ -16032,9 +16032,17 @@ Composite_literal_key_expression::do_lower(Gogo* gogo, Named_object*, Named_object* no = gogo->lookup(this->name_, NULL); if (no == NULL) { - go_error_at(this->location(), "reference to undefined name %qs", - Gogo::message_name(this->name_).c_str()); - return Expression::make_error(this->location()); + // Gogo::lookup doesn't look in the global namespace, and names + // used in composite literal keys aren't seen by + // Gogo::define_global_names, so we have to look in the global + // namespace ourselves. + no = gogo->lookup_global(Gogo::unpack_hidden_name(this->name_).c_str()); + if (no == NULL) + { + go_error_at(this->location(), "reference to undefined name %qs", + Gogo::message_name(this->name_).c_str()); + return Expression::make_error(this->location()); + } } return Expression::make_unknown_reference(no, this->location()); } |