From 0581e6ba3cfeb646553574aaa0efb1a822550a1f Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Thu, 9 Jan 2020 15:58:42 +0000 Subject: 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 --- gcc/go/gofrontend/expressions.h | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'gcc/go/gofrontend/expressions.h') diff --git a/gcc/go/gofrontend/expressions.h b/gcc/go/gofrontend/expressions.h index a0370e1..a4f892a 100644 --- a/gcc/go/gofrontend/expressions.h +++ b/gcc/go/gofrontend/expressions.h @@ -127,6 +127,7 @@ class Expression EXPRESSION_SLICE_CONSTRUCTION, EXPRESSION_MAP_CONSTRUCTION, EXPRESSION_COMPOSITE_LITERAL, + EXPRESSION_COMPOSITE_LITERAL_KEY, EXPRESSION_HEAP, EXPRESSION_RECEIVE, EXPRESSION_TYPE_DESCRIPTOR, @@ -384,6 +385,10 @@ class Expression make_composite_literal(Type*, int depth, bool has_keys, Expression_list*, bool all_are_names, Location); + // Make a composite literal key. + static Expression* + make_composite_literal_key(const std::string& name, Location); + // Make a struct composite literal. static Expression* make_struct_composite_literal(Type*, Expression_list*, Location); @@ -2881,8 +2886,7 @@ class Unknown_expression : public Parser_expression public: Unknown_expression(Named_object* named_object, Location location) : Parser_expression(EXPRESSION_UNKNOWN_REFERENCE, location), - named_object_(named_object), no_error_message_(false), - is_composite_literal_key_(false) + named_object_(named_object), no_error_message_(false) { } // The associated named object. @@ -2901,18 +2905,6 @@ class Unknown_expression : public Parser_expression set_no_error_message() { this->no_error_message_ = true; } - // Note that this expression is being used as the key in a composite - // literal, so it may be OK if it is not resolved. - void - set_is_composite_literal_key() - { this->is_composite_literal_key_ = true; } - - // Note that this expression should no longer be treated as a - // composite literal key. - void - clear_is_composite_literal_key() - { this->is_composite_literal_key_ = false; } - protected: Expression* do_lower(Gogo*, Named_object*, Statement_inserter*, int); @@ -2930,8 +2922,6 @@ class Unknown_expression : public Parser_expression // True if we should not give errors if this is undefined. This is // used if there was a parse failure. bool no_error_message_; - // True if this is the key in a composite literal. - bool is_composite_literal_key_; }; // An index expression. This is lowered to an array index, a string -- cgit v1.1