diff options
author | Ian Lance Taylor <iant@golang.org> | 2022-05-03 15:48:23 -0700 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2022-05-06 11:15:31 -0700 |
commit | 374b3c936d62c8b6e7c607fdf6e84a83748e85c7 (patch) | |
tree | 21202087f9734d2e493a5c9f19a7ff5086f7bc14 /gcc/go/gofrontend/expressions.cc | |
parent | 2fb654f77d5292864ef57040f7bc01d7a975f6d9 (diff) | |
download | gcc-374b3c936d62c8b6e7c607fdf6e84a83748e85c7.zip gcc-374b3c936d62c8b6e7c607fdf6e84a83748e85c7.tar.gz gcc-374b3c936d62c8b6e7c607fdf6e84a83748e85c7.tar.bz2 |
compiler: error for duplicate bool map keys
For golang/go#35945
Fixes golang/go#28104
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/403954
Diffstat (limited to 'gcc/go/gofrontend/expressions.cc')
-rw-r--r-- | gcc/go/gofrontend/expressions.cc | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc index 1b3b3bf..dce48e0 100644 --- a/gcc/go/gofrontend/expressions.cc +++ b/gcc/go/gofrontend/expressions.cc @@ -17266,6 +17266,8 @@ Composite_literal_expression::lower_map(Gogo* gogo, Named_object* function, Location location = this->location(); Unordered_map(unsigned int, std::vector<Expression*>) st; Unordered_map(unsigned int, std::vector<Expression*>) nt; + bool saw_false = false; + bool saw_true = false; if (this->vals_ != NULL) { if (!this->has_keys_) @@ -17300,6 +17302,7 @@ Composite_literal_expression::lower_map(Gogo* gogo, Named_object* function, continue; std::string sval; Numeric_constant nval; + bool bval; if ((*p)->string_constant_value(&sval)) // Check string keys. { unsigned int h = Gogo::hash_string(sval, 0); @@ -17373,6 +17376,19 @@ Composite_literal_expression::lower_map(Gogo* gogo, Named_object* function, mit->second.push_back(*p); } } + else if ((*p)->boolean_constant_value(&bval)) + { + if ((bval && saw_true) || (!bval && saw_false)) + { + go_error_at((*p)->location(), + "duplicate key in map literal"); + return Expression::make_error(location); + } + if (bval) + saw_true = true; + else + saw_false = true; + } } } |