{"record":{"id":"4b17eb1e2d604159","repo":"go-delve/delve","slug":"expression-q-s-does-not-support-indexing","errorCode":null,"errorMessage":"expression %q (%s) does not support indexing","messagePattern":"expression %q \\((.+?)\\) does not support indexing","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/eval.go","lineNumber":2200,"sourceCode":"\t\t\tif err != nil {\n\t\t\t\tstack.err = fmt.Errorf(\"can not index %s with %s\", xev.Name, astutil.ExprToString(op.Node.Index))\n\t\t\t\treturn\n\t\t\t}\n\t\t\tn = int64(n2)\n\t\t}\n\t\tthc, err := totalHitCountByID(scope.target.Breakpoints().Logical, int(n))\n\t\tif err == nil {\n\t\t\tstack.push(newConstant(constant.MakeUint64(thc), scope.BinInfo, scope.Mem))\n\t\t}\n\t\tstack.err = err\n\t\treturn\n\t}\n\n\tif xev.Flags&VariableCPtr == 0 {\n\t\txev = xev.maybeDereference()\n\t}\n\n\tcantindex := fmt.Errorf(\"expression %q (%s) does not support indexing\", astutil.ExprToString(op.Node.X), xev.TypeString())\n\n\tswitch xev.Kind {\n\tcase reflect.Ptr:\n\t\tif xev == nilVariable {\n\t\t\tstack.err = cantindex\n\t\t\treturn\n\t\t}\n\t\tif xev.Flags&VariableCPtr == 0 {\n\t\t\t_, isarrptr := xev.RealType.(*godwarf.PtrType).Type.(*godwarf.ArrayType)\n\t\t\tif !isarrptr {\n\t\t\t\tstack.err = cantindex\n\t\t\t\treturn\n\t\t\t}\n\t\t\txev = xev.maybeDereference()\n\t\t}\n\t\tfallthrough\n\n\tcase reflect.Slice, reflect.Array, reflect.String:","sourceCodeStart":2182,"sourceCodeEnd":2218,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/eval.go#L2182-L2218","documentation":"Declared locally as cantindex in evalArrayOrSliceExpression, this error states that the expression being indexed (after optional pointer dereference) has a Kind that supports no indexing at all. It is used for pointer cases where the pointer is nil (nilVariable), and for kinds like map/chan/struct/func that cannot be indexed, reporting 'expression %q (%s) does not support indexing'.","triggerScenarios":"Evaluating 'x[i]' where x is a nil pointer (VariableCPtr unset, maybeDereference yields nilVariable), or x is of a kind without indexing support (map handled elsewhere, struct, function, channel).","commonSituations":"Indexing through an uninitialized pointer ('p[0]' where p == nil), trying to index a func or chan value, or indexing a map via the wrong path so it falls through to this generic failure.","solutions":["Ensure the pointer is non-nil before indexing: check 'p != nil' or print p first.","Dereference explicitly and index the result: '(*p)[i]' rather than 'p[i]'.","Do not index maps/funcs/chans; for maps use 'm[key]' only if the map path is supported by your expression syntax, otherwise access members directly.","Index the underlying slice/array field of a struct: 's.data[i]' instead of 's[i]'."],"exampleFix":"// before (p is nil)\ndlv> print p[0]\n// error: expression \"p\" (*T) does not support indexing\n// after\ndlv> print p != nil && (*p)[0] != 0   // or fix p's assignment first","handlingStrategy":"validation","validationCode":"// Before indexing through a pointer, ensure it is non-nil:\n// p != nil && (*p)[0] ...\n// dlv> print p   // confirm non-nil and indexable kind","typeGuard":"// Only index pointers that are non-nil; other kinds are unsupported:\nif v := eval(xExpr); v.Kind == reflect.Ptr && v.isNil() {\n    return errors.New(\"cannot index through nil pointer\")\n}","tryCatchPattern":"res, err := scope.EvalExpression(indexExpr, cfg)\nif err != nil && strings.Contains(err.Error(), \"does not support indexing\") {\n    // dereference explicitly or index the underlying slice/array field\n}","preventionTips":["nil-check pointers before indexing through them","dereference explicitly: (*p)[i] instead of p[i]","do not attempt to index funcs, chans, or structs","index the backing slice field of wrapper structs directly"],"tags":["debugger","go","indexing","nil-pointer","unsupported-operation"],"backgroundTag":"expression-does-not-support-indexing","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}