diff mbox series

Go patch committed: Check duplicate implicit indexes in slices/arrays

Message ID CAOyqgcU550L+KmnrHBYx6aeUBEhmZxtrEnY7PvNqK8AtL+8Pow@mail.gmail.com
State New
Headers show
Series Go patch committed: Check duplicate implicit indexes in slices/arrays | expand

Commit Message

Ian Lance Taylor Feb. 5, 2019, 6:21 p.m. UTC
This patch by Ben Shi fixes the Go frontend to check duplicate
implicit indexes in slices/array composite literals.  This fixes
https://golang.org/issue/28186.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian
diff mbox series

Patch

Index: gcc/go/gofrontend/MERGE
===================================================================
--- gcc/go/gofrontend/MERGE	(revision 268465)
+++ gcc/go/gofrontend/MERGE	(working copy)
@@ -1,4 +1,4 @@ 
-047b0aa6a29d46fde99b3e5823339ac8866f797c
+347628daf153baf3034b61b2abb4ec39e2ab37c8
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
Index: gcc/go/gofrontend/expressions.cc
===================================================================
--- gcc/go/gofrontend/expressions.cc	(revision 268369)
+++ gcc/go/gofrontend/expressions.cc	(working copy)
@@ -14244,6 +14244,13 @@  Composite_literal_expression::lower_arra
 
       if (index_expr == NULL)
 	{
+	  if (std::find(indexes->begin(), indexes->end(), index)
+	      != indexes->end())
+	    {
+	      go_error_at(val->location(),
+			  "duplicate value for index %lu", index);
+	      return Expression::make_error(location);
+	    }
 	  if (!indexes->empty())
 	    indexes->push_back(index);
 	}