Skip to content

Breaked merge of bool pointers in 0.3.8 #131

@xt99

Description

@xt99

Hello,
First of all, I would like to thanks contributors for this great library!

We use mergo a lot in our project for merging structs. We have bools there and I'm aware about the issues with merging false values (which can be empty or can be set by user) to the true values. This is why we're using pointers to booleans. Following code worked well with 0.3.7 version and was giving us correct values when overriding *true with *false:

package main

import (
	"fmt"
	"github.com/imdario/mergo"
)

type Foo struct {
	A *bool
	B string
}

func main() {
	src := Foo{
		A: func(v bool) *bool { return &v }(false),
		B: "src",
	}
	dest := Foo{
		A: func(v bool) *bool { return &v }(true),
		B: "dest",
	}
	mergo.Merge(&dest, src, mergo.WithOverride)
	fmt.Println(*dest.A, dest.B)
	// Should print "false src" because of override
}

But 0.3.8 version breaks this correct result of false src for this code and gives us wrong true src value now.

Can you please take a look on this issue? Thank you very much!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions