Patchwork Go patch committed: Fix composite literal with enclosing var as key

login
register
mail settings
Submitter Ian Taylor
Date July 16, 2013, 10:45 p.m.
Message ID <mcrhafuf7jl.fsf@iant-glaptop.roam.corp.google.com>
Download mbox | patch
Permalink /patch/259535/
State New
Headers show

Comments

Ian Taylor - July 16, 2013, 10:45 p.m.
This patch to the Go frontend fixes a bug when there is a composite
literal that uses a struct field where the name of the field happens to
be the same as the name of a variable in an enclosing function.  This
used to work fine, but it broke when I added a new field to function
closures as part of the change to the function representation.  I've
added a test to the master Go repository to catch this in the future.
Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline and 4.8 branch.

Ian

Patch

diff -r a1afec89faee go/gogo.cc
--- a/go/gogo.cc	Tue Jul 16 08:44:25 2013 -0700
+++ b/go/gogo.cc	Tue Jul 16 15:41:23 2013 -0700
@@ -3380,7 +3380,7 @@ 
   st->push_field(Struct_field(Typed_identifier(".$f", voidptr_type,
 					       this->location_)));
 
-  unsigned int index = 0;
+  unsigned int index = 1;
   for (Closure_fields::const_iterator p = this->closure_fields_.begin();
        p != this->closure_fields_.end();
        ++p, ++index)