{"record":{"id":"d9adc7adafcc27ef","repo":"go-delve/delve","slug":"can-not-index-s-with-s","errorCode":null,"errorMessage":"can not index %s with %s","messagePattern":"can not index (.+?) with (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/eval.go","lineNumber":2183,"sourceCode":"\t\tstack.err = xev.Unreadable\n\t\treturn\n\t}\n\n\tif xev.Name == evalop.BreakpointHitCountVarNameQualified {\n\t\tif idxev.Kind == reflect.String {\n\t\t\ts := constant.StringVal(idxev.Value)\n\t\t\tthc, err := totalHitCountByName(scope.target.Breakpoints().Logical, s)\n\t\t\tif err == nil {\n\t\t\t\tstack.push(newConstant(constant.MakeUint64(thc), scope.BinInfo, scope.Mem))\n\t\t\t}\n\t\t\tstack.err = err\n\t\t\treturn\n\t\t}\n\t\tn, err := idxev.asInt()\n\t\tif err != nil {\n\t\t\tn2, err := idxev.asUint()\n\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","sourceCodeStart":2165,"sourceCodeEnd":2201,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/eval.go#L2165-L2201","documentation":"In evalArrayOrSliceExpression, the index expression must evaluate to an integer (or unsigned integer). When both idxev.asInt() and idxev.asUint() fail — the index is a string, float, bool, or otherwise non-numeric — the evaluator errors with 'can not index <x> with <index-expr>'. The check at this site also feeds breakpoint hit-count indexing.","triggerScenarios":"Evaluating 'arr[<expr>]' where <expr> does not evaluate to an integer value, e.g. 'arr[\"key\"]', 'arr[3.5]', 'sl[true]', or indexing with a struct/pointer-typed variable; also indexing breakpoint logical hit counts with a non-integer index.","commonSituations":"Copy-pasting map-style access ('m[\"k\"]' syntax applied to slices/arrays), forgetting that map indexing is handled by a different path, or using a wrongly-typed loop variable in a condition.","solutions":["Use an integer index expression: 'sl[2]' or 'sl[i]' where i is an int variable.","If the operand is a map, ensure the map-index path is used (map[string]X supports 'm[\"key\"]'); slices/arrays do not.","Cast or convert the index: use an int-typed variable instead of a float or string.","Check for typos where the index variable shadows a differently-typed symbol."],"exampleFix":"// before\ndlv> print sl[\"0\"]\n// error: can not index sl with \"0\"\n// after\ndlv> print sl[0]","handlingStrategy":"validation","validationCode":"// Use integer literals or int-typed variables as indices:\n// sl[0], sl[i]\n// Never: sl[\"key\"], sl[3.5], sl[flag]","typeGuard":"// Pre-validate the index expression kind before composing indexing:\nif v := eval(idxExpr); v.Kind != reflect.Int && !isUintKind(v.Kind) {\n    return fmt.Errorf(\"index %s must be an integer\", idxExpr)\n}","tryCatchPattern":"res, err := scope.EvalExpression(indexExpr, cfg)\nif err != nil && strings.Contains(err.Error(), \"can not index\") {\n    // fix the index to an integer expression\n}","preventionTips":["use int indices for slices/arrays; map syntax only for maps","avoid float, string, bool indices","check variable types when loop variables are used as indices","convert or cast indices to int before indexing"],"tags":["debugger","go","indexing","type-mismatch"],"backgroundTag":"invalid-index-type","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}