{"id":"e7d546a69f4cfb51","repo":"gohugoio/hugo","slug":"intersect-does-not-support-slices-or-arrays-of-unc","errorCode":null,"errorMessage":"intersect does not support slices or arrays of uncomparable types","messagePattern":"intersect does not support slices or arrays of uncomparable types","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/collections/collections.go","lineNumber":289,"sourceCode":"func (ns *Namespace) Intersect(l1, l2 any) (any, error) {\n\tif l1 == nil || l2 == nil {\n\t\treturn make([]any, 0), nil\n\t}\n\n\tvar ins *intersector\n\n\tl1v := reflect.ValueOf(l1)\n\tl2v := reflect.ValueOf(l2)\n\n\tswitch l1v.Kind() {\n\tcase reflect.Array, reflect.Slice:\n\t\tins = &intersector{r: reflect.MakeSlice(l1v.Type(), 0, 0), seen: make(map[any]bool)}\n\t\tswitch l2v.Kind() {\n\t\tcase reflect.Array, reflect.Slice:\n\t\t\tfor i := range l1v.Len() {\n\t\t\t\tl1vv := l1v.Index(i)\n\t\t\t\tif !l1vv.Type().Comparable() {\n\t\t\t\t\treturn make([]any, 0), errors.New(\"intersect does not support slices or arrays of uncomparable types\")\n\t\t\t\t}\n\n\t\t\t\tfor j := range l2v.Len() {\n\t\t\t\t\tl2vv := l2v.Index(j)\n\t\t\t\t\tif !l2vv.Type().Comparable() {\n\t\t\t\t\t\treturn make([]any, 0), errors.New(\"intersect does not support slices or arrays of uncomparable types\")\n\t\t\t\t\t}\n\n\t\t\t\t\tins.handleValuePair(l1vv, l2vv)\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn ins.r.Interface(), nil\n\t\tdefault:\n\t\t\treturn nil, errors.New(\"can't iterate over \" + reflect.ValueOf(l2).Type().String())\n\t\t}\n\tdefault:\n\t\treturn nil, errors.New(\"can't iterate over \" + reflect.ValueOf(l1).Type().String())\n\t}","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/tpl/collections/collections.go#L271-L307","documentation":"`intersect` compares elements from both slices using them as map keys and `==`-style comparison, so every element type must be comparable in the Go sense. Elements that are slices, maps, or functions (e.g. []string values inside a [][]string, or map params) are uncomparable and cause this error while iterating either input.","triggerScenarios":"`{{ intersect $a $b }}` where either slice contains slice/map elements — e.g. intersecting `.Params.tagGroups` (a list of lists from YAML) or slices of dicts built with `slice (dict ...) (dict ...)`.","commonSituations":"Front-matter params that are nested lists/maps being fed to intersect for related-content logic, or accidentally intersecting page-param collections whose YAML values decoded as maps instead of scalars.","solutions":["Intersect slices of scalars (strings, numbers) or Pages — flatten nested structures first, e.g. intersect on `.Params.tags` rather than a list of tag objects.","Extract a comparable key from each element before intersecting: build a slice of IDs/strings with `range`+`append`, intersect those, then map back.","For related pages, prefer Hugo's built-in `.Site.RegularPages.Related` / related-content config instead of manual intersects over complex params."],"exampleFix":"<!-- before -->\n{{ $common := intersect .Params.groups $other.Params.groups }} <!-- groups: list of maps -->\n<!-- after -->\n{{ $a := slice }}{{ range .Params.groups }}{{ $a = $a | append .name }}{{ end }}\n{{ $b := slice }}{{ range $other.Params.groups }}{{ $b = $b | append .name }}{{ end }}\n{{ $common := intersect $a $b }}","handlingStrategy":"type-guard","validationCode":"{{/* intersect only works on slices of comparable scalars or Pages */}}\n{{ $a := slice \"x\" \"y\" }}{{ $b := slice \"y\" \"z\" }}\n{{ $both := intersect $a $b }}","typeGuard":"{{/* flatten slices-of-slices or maps to comparable keys first */}}\n{{ $keys := slice }}\n{{ range $m := $items }}{{ $keys = $keys | append (index $m \"id\") }}{{ end }}","tryCatchPattern":null,"preventionTips":["Intersect slices of comparable values (strings, numbers) or Pages — not slices of maps, slices, or funcs","Project maps/structs down to a comparable key field (id, slug) before intersecting","Use `where` with `in` as an alternative when comparing complex objects by a field"],"tags":["hugo","templates","collections","intersect","comparable-types"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}