Comments (7)
@lakhgupt @anderssonw @designtesbrot @mdelapenya @vedhavyas @beauso @erikreinert dest.C
has false
value, and src.C
has true
value. According to the documentation:
Mergo merges same-type structs and maps by setting default values in zero-value fields.
false
is the zero value for booleans:
When storage is allocated for a variable, either through a declaration or a call of new, or when a new value is created, either through a composite literal or a call of make, and no explicit initialization is provided, the variable or value is given a default value. Each element of such a variable or value is set to the zero value for its type: false for booleans, 0 for numeric types, "" for strings, and nil for pointers, functions, interfaces, slices, channels, and maps.
The example is coherent with the stated behaviour.
About overwriting - assuming no mergo.WithOverwrite
is used - I didn't reproduce it using the playground example by switching dest.C
and src.C
(so dest.C
is already true
):
package main
import (
"fmt"
"dario.cat/mergo"
)
type Foo struct {
A string
B int64
C bool
D int64
}
func main() {
src := Foo{
A: "five",
B: 5,
C: false,
D: 10,
}
dest := Foo{
C: true,
B: 3,
D: 11,
}
mergo.Merge(&dest, src)
fmt.Println(src)
fmt.Println(dest)
}
// Output:
// {five 5 false 10}
// {five 3 true 11}
from mergo.
I'm seeing this issue, any thoughts on why this is happeneing ?
from mergo.
fyi, just reproduced this too.
from mergo.
Also recently noticed this. I might have expected false -> true overwriting, but we have true -> false overwriting which is definitely not the expected behaviour.
from mergo.
@darccio This is not what we experienced, the code block you mention is expected, but irrelevant. We were given true -> false
, when the src
had a non-zero field, which does not coincide with the expected behaviour. Unless something has been done to circumvent this, please re-open the issue.
from mergo.
@anderssonw Please provide and example. The library is simple enough and there are no more foreseeable ways that can lead to the described issue.
If I can't reproduce it, I can't fix it.
from mergo.
Luckily it seems I was mistaken in our case :)
We updated the destination struct by mistakenly having both the source and destination refer to a single struct called cron
, when the sources cron
was update, so was of course the destination, leading to me thinking it was mergo. Thanks for rubber ducking I guess ๐
from mergo.
Related Issues (20)
- Merge use references to src instead of deep copying HOT 1
- Determine whether to execute a custom transformer according to the types of SRC and DST HOT 2
- Transformers: How to access underlying datatype HOT 1
- mergo WithSliceDeepCopy into differen types will causes painc
- Missing merge only empty dst and check empty value not work for struct HOT 1
- WithSliceDeepCopy cannot merge nums in slice. Suggestion: Recomplete it as WithRecursiveOverride HOT 1
- Mergo not overriding destination with source HOT 2
- Docs: โMergo in the wildโ inaccurate HOT 2
- Mergo is not overriding destination map key with empty value with WithOverwriteWithEmptyValue
- Add support OSS-Fuzz
- Merge Slices HOT 6
- New module path breaks go install of package with indirect dependency on mergo HOT 13
- How to overwrite specified field with empty value in struct HOT 1
- Choosing fields of struct to override
- Vanity name makes live hard for developers HOT 9
- Vanity url doesn't redirect to github repo HOT 5
- module declares its path as: dario.cat/mergo but was required as: github.com/imdario/mergo HOT 7
- bool issue HOT 2
- unable to go get package
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mergo.