https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65755

            Bug ID: 65755
           Summary: incorrect reflection of struct fields with gccgo
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: go
          Assignee: ian at airs dot com
          Reporter: boger at us dot ibm.com
                CC: cmang at google dot com
            Target: ppc64le, ppc64, x86_64

packer testcase fails due to incorrect reflected struct field when test is
built with gccgo.  Failure occurs with gccgo on ppc64le and x86_64 but works
when built with gc for both.

I've tried to reproduce this in a smaller testcase but have not been able to. 
I'm not 100% sure the code is correct go code but I couldn't find anything to
tell me otherwise, and since it works with gc and works in my smaller testcase
with gccgo it seems like it must be correct.

To build the app and the testsuite follow the directions here
https://github.com/mitchellh/packer#developing-packer

When doing 'make' the testsuite is run, and there are two failures.  The
failure documented in this bugzilla is:

FAIL    github.com/mitchellh/packer/fix

In github.com/mitchellh/packer/fix there are several files which declare the
template struct within a function as follows:

        // Our template type we'll use for this fixer only
        type template struct {
                Builders []map[string]interface{}
        }

However in fixer_pp_vagrant_override.go the template struct is declared like
this:

        type template struct {
                PostProcessors []interface{} `mapstructure:"post-processors"`
        }

In all cases, the template struct is passed to another function which uses the
reflect package to look at the fields of the struct.  The field obtained using
these functions is inccorect and causes the test to fail because of unexpected
results.  It should see PostProcessors as the field but instead it sees the
field as Builders.

I added the following print statements to display the field before the call
which demonstrate the incorrect fields.  This is in
fixer_pp_vagrant_override.go:

func (FixerVagrantPPOverride) Fix(input map[string]interface{})
(map[string]interface{}, error) {
        // Our template type we'll use for this fixer only
        type template struct {
                PostProcessors []interface{} `mapstructure:"post-processors"`
        }

        // Decode the input into our structure, if we can
        var tpl template
        val := reflect.ValueOf(tpl)
        field := val.Type().Field(0)
        fmt.Printf("### field: %s ###\n", field)

And the output looks like this:

### field: {Builders  []map[string]interface {}  %!s(uintptr=0) [%!s(int=0)]
%!s(bool=false)} ###
--- FAIL: TestFixerVagrantPPOverride_Fix (0.00s)
    testing.go:278: unexpected: map[string]interface
{}{"post-processors":[]interface {}(nil)}
        expected: map[string]interface {}{"post-processors":[]interface
{}{"foo", map[string]interface {}{"override":map[string]interface
{}{"aws":map[string]interface {}{"foo":"bar"}}, "type":"vagrant"},
map[string]interface {}{"type":"vsphere"}, []interface {}{map[string]interface
{}{"override":map[string]interface {}{"vmware":map[string]interface
{}{"foo":"bar"}}, "type":"vagrant"}}}}
FAIL

Reply via email to