-
-
Notifications
You must be signed in to change notification settings - Fork 269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix merging of interface types with concrete values #106
Conversation
@admtnnr Thanks for the PR. Can you describe a bit more why is this needed (which use cases, …) ? |
@vdemeester sure, here's the case I ran into: type Doer interface {
Do() error
} And we have two implementations of that interface: type NoopDoer string
func (d NoopDoer) Do() error { return nil }
type RealDoer struct { ... }
func (d RealDoer) Do() error {
...
return nil
} And we have our config struct like so: type config struct {
Doer Doer
} And we set up a "default" config that we will merge in that uses the var defaultConfig = config{
Doer: NoopDoer("this does nothing"),
} What I've encountered is that the call to var myConfig = config{
Doer: RealDoer{},
}
if err := mergo.Merge(&myConfig, defaultConfig); err != nil {
panic("THIS WILL GET RUN")
} So what actually seems to happen is that It skips through this case since the underlying types aren't the same: https://github.com/imdario/mergo/pull/106/files#diff-a103b5fee5fb31abebf12ee067c01da8R190 and instead hits this line: https://github.com/imdario/mergo/pull/106/files#diff-a103b5fee5fb31abebf12ee067c01da8R195 The test I added will fail if the check for Hopefully that helps explain it a little better. It's a weird case, I'll give you that. :) |
@admtnnr indeed 😅 |
@admtnnr btw can you rebase against master to fix the CI ? 👼 |
@vdemeester Rebased. |
@vdemeester let me know if there's anything else you need from me to get this merged. :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM :tiger:
full diff: darccio/mergo@v0.3.7...v0.3.8 includes: - darccio/mergo#112 Add strict override - fixes darccio/mergo#111 WithOverride should be able to check types - darccio/mergo#106 Fix merging of interface types with concrete values - darccio/mergo#120 should not overwrite pointers directly, instead check embedded values - fixes darccio/mergo#114 Embedded struct of pointer types will overwrite the whole destination struct - darccio/mergo#125 added WithOverrideEmptySlice config flag Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
full diff: darccio/mergo@v0.3.7...v0.3.8 includes: - darccio/mergo#112 Add strict override - fixes darccio/mergo#111 WithOverride should be able to check types - darccio/mergo#106 Fix merging of interface types with concrete values - darccio/mergo#120 should not overwrite pointers directly, instead check embedded values - fixes darccio/mergo#114 Embedded struct of pointer types will overwrite the whole destination struct - darccio/mergo#125 added WithOverrideEmptySlice config flag Signed-off-by: Sebastiaan van Stijn <github@gone.nl> Upstream-commit: 9bd1b1a8eca97a2403bc7a2ed9a52427d8c27078 Component: engine
full diff: darccio/mergo@v0.3.7...v0.3.8 includes: - darccio/mergo#112 Add strict override - fixes darccio/mergo#111 WithOverride should be able to check types - darccio/mergo#106 Fix merging of interface types with concrete values - darccio/mergo#120 should not overwrite pointers directly, instead check embedded values - fixes darccio/mergo#114 Embedded struct of pointer types will overwrite the whole destination struct - darccio/mergo#125 added WithOverrideEmptySlice config flag Signed-off-by: Sebastiaan van Stijn <github@gone.nl> Signed-off-by: zach <Zachary.Joyner@linux.com>
full diff: darccio/mergo@v0.3.7...v0.3.8 includes: - darccio/mergo#112 Add strict override - fixes darccio/mergo#111 WithOverride should be able to check types - darccio/mergo#106 Fix merging of interface types with concrete values - darccio/mergo#120 should not overwrite pointers directly, instead check embedded values - fixes darccio/mergo#114 Embedded struct of pointer types will overwrite the whole destination struct - darccio/mergo#125 added WithOverrideEmptySlice config flag Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
full diff: darccio/mergo@v0.3.7...v0.3.8 includes: - darccio/mergo#112 Add strict override - fixes darccio/mergo#111 WithOverride should be able to check types - darccio/mergo#106 Fix merging of interface types with concrete values - darccio/mergo#120 should not overwrite pointers directly, instead check embedded values - fixes darccio/mergo#114 Embedded struct of pointer types will overwrite the whole destination struct - darccio/mergo#125 added WithOverrideEmptySlice config flag Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
full diff: darccio/mergo@v0.3.7...v0.3.8 includes: - darccio/mergo#112 Add strict override - fixes darccio/mergo#111 WithOverride should be able to check types - darccio/mergo#106 Fix merging of interface types with concrete values - darccio/mergo#120 should not overwrite pointers directly, instead check embedded values - fixes darccio/mergo#114 Embedded struct of pointer types will overwrite the whole destination struct - darccio/mergo#125 added WithOverrideEmptySlice config flag Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
full diff: darccio/mergo@v0.3.7...v0.3.8 includes: - darccio/mergo#112 Add strict override - fixes darccio/mergo#111 WithOverride should be able to check types - darccio/mergo#106 Fix merging of interface types with concrete values - darccio/mergo#120 should not overwrite pointers directly, instead check embedded values - fixes darccio/mergo#114 Embedded struct of pointer types will overwrite the whole destination struct - darccio/mergo#125 added WithOverrideEmptySlice config flag Signed-off-by: Sebastiaan van Stijn <github@gone.nl> Upstream-commit: 6cf7970cd397a77155aec077bd27755bc033b6f4 Component: cli
full diff: darccio/mergo@v0.3.7...v0.3.8 includes: - darccio/mergo#112 Add strict override - fixes darccio/mergo#111 WithOverride should be able to check types - darccio/mergo#106 Fix merging of interface types with concrete values - darccio/mergo#120 should not overwrite pointers directly, instead check embedded values - fixes darccio/mergo#114 Embedded struct of pointer types will overwrite the whole destination struct - darccio/mergo#125 added WithOverrideEmptySlice config flag Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
No description provided.