mergo icon indicating copy to clipboard operation
mergo copied to clipboard

Merge without override assume false is a valid non empty type

Open kotyara85 opened this issue 4 years ago • 3 comments

Here's an example

type Option struct {
	test    bool
}

o := Option{}

mergo.Merge(&o, &Option{test: true})

In this example test will be false. WithOverride won't really work here, because any other type will be overwritten in this case. I guess custom transformers will help here?

kotyara85 avatar Nov 19 '21 22:11 kotyara85

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 Nov 19 '21 22:11 xscode-auto-reply[bot]

According to docs this is expected behavior Mergo won't merge unexported (private) fields Rename field test to Test and it will work as expected

nilsgstrabo avatar Dec 09 '21 11:12 nilsgstrabo

I don't think this problem is just unexported variables. I think any false is considered empty and thus doesn't have the expected behavior.

rfay avatar Aug 04 '22 15:08 rfay

@rfay I confirm it's just unexported variables, as @nilsgstrabo pointed. If you test it exporting test, it works as expected (no false value overrides a true value).

darccio avatar Sep 11 '23 11:09 darccio