mergo icon indicating copy to clipboard operation
mergo copied to clipboard

Merge with mergo.WithOverride gives unexpected behavior

Open mtt0 opened this issue 3 years ago • 2 comments

package main

import (
	"fmt"
	"github.com/imdario/mergo"
)

type Foo struct {
	A string
	B int64
}

func main() {
	src := Foo{
		A: "one",
		B: 2,
	}
	dest := Foo{
		A: "two",
	}
	mergo.Merge(&dest, src, mergo.WithOverride)
	fmt.Println(dest)
	// Will print
	// {one 2}
	// Expect
	// {two 2}
}
  • mergo.Merge(&dest, src, mergo.WithOverride) gives {one 2}
  • mergo.Merge(&dest, src) gives {two 2}

https://github.com/imdario/mergo/blob/29fb3d3bdc5512887f1dc9aedde6a0fed407fa8f/merge.go#L313

Go PlayGround

mtt0 avatar Mar 11 '21 08:03 mtt0

Thanks for opening a new issue. The team has been notified and will review it as soon as possible. For urgent issues and priority support, visit https://xscode.com/imdario/mergo

xscode-auto-reply[bot] avatar Mar 11 '21 08:03 xscode-auto-reply[bot]

@mtt0 Why is it unexpected?

darccio avatar Mar 22 '21 09:03 darccio