{"record":{"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/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/collections/collections.go#L271-L307","documentation":"Intersect (collections.go:288-290) builds a seen map keyed by element value (intersector.seen is map[any]bool at line 283), which requires l1's element type to be comparable. Slices, maps, funcs as elements are not comparable and are rejected per-element.","triggerScenarios":"{{ intersect $sliceOfSlices $other }} where l1 element type is []int, []string, map[...], or any non-comparable type.","commonSituations":"Intersecting collections of slices; Pages whose struct contains a slice field making the type non-comparable; [][]int.","solutions":["Intersect only comparable element types (strings, numbers, comparable structs)","Map elements to a comparable key (e.g. .File.Path) before intersecting","Reformulate using Uniq + In over a flattened comparable collection"],"exampleFix":"// before\n{{ intersect $sliceOfSlices $b }}\n// after\n{{ intersect (apply $sliceOfSlices \"string\") (apply $b \"string\") }}","handlingStrategy":"type-guard","validationCode":"{{/* project to a comparable key (string) before intersect */}}\n{{ $a := apply $a \"string\" }}\n{{ $b := apply $b \"string\" }}\n{{ intersect $a $b }}","typeGuard":"{{/* Go-side */}}\nfunc elemTypeIsComparable(v any) bool {\n  t := reflect.TypeOf(v)\n  if t.Kind() != reflect.Slice && t.Kind() != reflect.Array {\n    return false\n  }\n  return t.Elem().Comparable()\n}","tryCatchPattern":null,"preventionTips":["Intersect only comparable element types (strings, numbers, comparable structs)","Project elements to a comparable key (e.g. .File.Path) first","Avoid slices-of-slices/maps/funcs as intersect operands"],"tags":["hugo","go-template","collections","type-mismatch","reflect","comparable"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}