Skip to content

Commit

Permalink
Initial fix for underlying struct mis-match bug
Browse files Browse the repository at this point in the history
Update cmd/packer-sdc/internal/mapstructure-to-hcl2/mapstructure-to-hcl2.go

Co-authored-by: Lucas Bajolet <105649352+lbajolet-hashicorp@users.noreply.github.com>
  • Loading branch information
nywilken and lbajolet-hashicorp committed Oct 27, 2023
1 parent c170d73 commit 4fb8273
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,16 @@ func (cmd *Command) Run(args []string) int {
if !utOk {
continue
}

pos := sort.SearchStrings(typeNames, id.Name)
if pos >= len(typeNames) || typeNames[pos] != id.Name {
continue // not a struct we care about
}
// Sometimes we see the underlying struct for a similar named type, which results
// in an incorrect FlatMap. If the type names are not exactly the same skip.
if nt.Obj().Name() != id.Name {
continue // not the struct we are looking for
}
// make sure each type is found once where somehow sometimes they can be found twice
typeNames = append(typeNames[:pos], typeNames[pos+1:]...)
flatenedStruct, err := getMapstructureSquashedStruct(obj.Pkg(), utStruct)
Expand Down

0 comments on commit 4fb8273

Please sign in to comment.