Skip to content
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

use *bool as nullable boolean #127

Closed
tvojacek opened this issue Oct 30, 2019 · 3 comments
Closed

use *bool as nullable boolean #127

tvojacek opened this issue Oct 30, 2019 · 3 comments

Comments

@tvojacek
Copy link

proposal use *bool as nullable boolean
mergo will copy any not nil value to dst

index 3fb6c64..80e733b 100644
--- a/merge.go
+++ b/merge.go
@@ -170,6 +170,13 @@ func deepMerge(dst, src reflect.Value, visited map[uintptr]*visit, depth int, co
dst.Set(reflect.AppendSlice(dst, src))
}
case reflect.Ptr:

  •           if src.IsNil() {
    
  •                   break
    
  •           }
    
  •           if dst.Elem().Kind()==reflect.Bool{
    
  •                   dst.Set(src)
    
  •                   break
    
  •           }
              fallthrough
      case reflect.Interface:
              if src.IsNil() {
    
@JackQuincy
Copy link

This broke my team on the latest vendor after this change #120 before we could use a *bool to allow false to overwrite true. But with that change it no longer works. I'd like it if mergo can look at the pointer and see if the Elem().Kind() is a native type(not pointer or struct? or just int, bool etc.) and allow zero value to overwrite a non zero value. And make nil the value that doesn't merge. For now we are going to have to switch from *bool to *enum that has 'true', 'false', and a zero value 'invalid'

@github4jiawen
Copy link

Duplicate of #89

@darccio
Copy link
Owner

darccio commented May 17, 2020

I don't think this is really a duplicate of #89, but a duplicate of #131

@JackQuincy sorry for the issue, you should be able to go back to merge bool pointers using mergo.WithOverwriteWithEmptyValue in next release 0.3.10. Actually, you won't need to use bool pointers, as this affects any false value that is going to be merge.

@darccio darccio closed this as completed May 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants