go-delve/delve · error
expression %q (%s) does not support indexing
Error message
expression %q (%s) does not support indexing
What it means
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'.
Source
Thrown at pkg/proc/eval.go:2200
if err != nil {
stack.err = fmt.Errorf("can not index %s with %s", xev.Name, astutil.ExprToString(op.Node.Index))
return
}
n = int64(n2)
}
thc, err := totalHitCountByID(scope.target.Breakpoints().Logical, int(n))
if err == nil {
stack.push(newConstant(constant.MakeUint64(thc), scope.BinInfo, scope.Mem))
}
stack.err = err
return
}
if xev.Flags&VariableCPtr == 0 {
xev = xev.maybeDereference()
}
cantindex := fmt.Errorf("expression %q (%s) does not support indexing", astutil.ExprToString(op.Node.X), xev.TypeString())
switch xev.Kind {
case reflect.Ptr:
if xev == nilVariable {
stack.err = cantindex
return
}
if xev.Flags&VariableCPtr == 0 {
_, isarrptr := xev.RealType.(*godwarf.PtrType).Type.(*godwarf.ArrayType)
if !isarrptr {
stack.err = cantindex
return
}
xev = xev.maybeDereference()
}
fallthrough
case reflect.Slice, reflect.Array, reflect.String:View on GitHub (pinned to a23773e6c3)
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]'.
Example fix
// before (p is nil) dlv> print p[0] // error: expression "p" (*T) does not support indexing // after dlv> print p != nil && (*p)[0] != 0 // or fix p's assignment first
Defensive patterns
Strategy: validation
Validate before calling
// Before indexing through a pointer, ensure it is non-nil: // p != nil && (*p)[0] ... // dlv> print p // confirm non-nil and indexable kind
Type guard
// Only index pointers that are non-nil; other kinds are unsupported:
if v := eval(xExpr); v.Kind == reflect.Ptr && v.isNil() {
return errors.New("cannot index through nil pointer")
} Try / catch
res, err := scope.EvalExpression(indexExpr, cfg)
if err != nil && strings.Contains(err.Error(), "does not support indexing") {
// dereference explicitly or index the underlying slice/array field
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- nil can not be dereferenced
- nil pointer dereference
- can not index %s with %s
- can not index %q
- could not decode first frame
AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31).
Data as JSON: /api/errors/4b17eb1e2d604159.
Report an issue: GitHub.