Skip to content

FLAG_IGNORE_SLICE_ORDER - panic: runtime error: hash of unhashable type map[string]interface {} #60

@sschulz-t

Description

@sschulz-t

Please see the example 5) from this playground: https://go.dev/play/p/M-VZFkXte9T

With FLAG_IGNORE_SLICE_ORDER set, it causes a panic.

It happens at:

func (c *cmp) equals(a, b reflect.Value, level int) {
...
am[a.Index(i).Interface()] += 1
...
}

where the code tries to use the map[string]interface{} as a key when the child is a slice.

When reading the comments in the code:

	// FLAG_IGNORE_SLICE_ORDER causes Equal to ignore slice order so that
	// []int{1, 2} and []int{2, 1} are equal. Only slices of primitive scalars
	// like numbers and strings are supported. Slices of complex types,
	// like []T where T is a struct, are undefined because Equal does not
	// recurse into the slice value when this flag is enabled.

This states it is unsupported to use it with this type of data. I was wondering if it is possible to add this feature in the future.
At least this ticket could save others some time when they do a web search for the cause of the error and did not read the documentation ;)

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