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

v0.3.9 returns an error on merge when fields are of different types #152

Closed
kirk-patton opened this issue Jul 2, 2020 · 2 comments
Closed

Comments

@kirk-patton
Copy link

This works in v0.3.8 and earlier, but returns and error in v0.3.9


import (
	"github.com/davecgh/go-spew/spew"
	"github.com/imdario/mergo"
	"gopkg.in/yaml.v2"
)

type Foo map[interface{}]interface{}

func main() {
	// v0.3.9: error on different types to merge
	// cannot append two different types (int, string)

	// v0.3.8: and earlier allow this
	//
	// There is a mergo.WithTypeCheck(c *Config)
	// but that defaults to false, so this behavior is
	// unexpected

	config := `foo: "1"`
	defaultConfig := `foo: 1`

	var (
		configMap  map[interface{}]interface{}
		defaultMap map[interface{}]interface{}
	)

	err := yaml.Unmarshal([]byte(config), &configMap)
	if err != nil {
		panic(err)
	}

	err = yaml.Unmarshal([]byte(defaultConfig), &defaultMap)
	if err != nil {
		panic(err)
	}

	// v0.3.9 returns an error
	// versions <= v0.3.8 do not
	err = mergo.Merge(&configMap, &defaultMap)
	if err != nil {
		panic(err)
	}

	spew.Dump(configMap)

}```

[Demonstration Code](https://github.com/kirk-patton/mergo)
@kirk-patton
Copy link
Author

This may be related to: #143

@darccio
Copy link
Owner

darccio commented Jul 17, 2020

@kirk-patton It is the same bug. Closing this issue in favour of the other.

@darccio darccio closed this as completed Jul 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

2 participants