Skip to content

When diffing an embedded pointer field against nil, the comparison should continue rather than break, and it should output a bunch of JSON. #118

@kom0055

Description

@kom0055

I suggest that , When diffing an embedded pointer field against nil, the comparison should continue rather than break, and it should output a bunch of JSON.
If it infect too widely ,might as well use extra param

func (d *Differ) diffPtr(path []string, a, b reflect.Value, parent interface{}) error {
	if a.Kind() != b.Kind() {
		if a.Kind() == reflect.Invalid {
			if !b.IsNil() {
				return d.diff(path, reflect.ValueOf(nil), reflect.Indirect(b), parent)
			}

			d.cl.Add(CREATE, path, nil, exportInterface(b), parent)
			return nil
		}

		if b.Kind() == reflect.Invalid {
			if !a.IsNil() {
				return d.diff(path, reflect.Indirect(a), reflect.ValueOf(nil), parent)
			}

			d.cl.Add(DELETE, path, exportInterface(a), nil, parent)
			return nil
		}

		return ErrTypeMismatch
	}

	if a.IsNil() && b.IsNil() {
		return nil
	}

	if a.IsNil() {
		d.cl.Add(UPDATE, path, nil, exportInterface(b), parent)
		return nil
	}

	if b.IsNil() {
		d.cl.Add(UPDATE, path, exportInterface(a), nil, parent)
		return nil
	}

	return d.diff(path, reflect.Indirect(a), reflect.Indirect(b), parent)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions