{"record":{"id":"35c3bd6d204eeb9d","repo":"go-delve/delve","slug":"can-not-slice-q","errorCode":null,"errorMessage":"can not slice %q","messagePattern":"can not slice %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/eval.go","lineNumber":2273,"sourceCode":"\t\thigh, err = stack.pop().asInt()\n\t\tif err != nil {\n\t\t\tstack.err = err\n\t\t\treturn\n\t\t}\n\t}\n\txev := stack.pop()\n\tif xev.Unreadable != nil {\n\t\tstack.err = xev.Unreadable\n\t\treturn\n\t}\n\tif !op.HasHigh {\n\t\thigh = xev.Len\n\t}\n\n\tswitch xev.Kind {\n\tcase reflect.Slice, reflect.Array, reflect.String:\n\t\tif xev.Base == 0 {\n\t\t\tstack.err = fmt.Errorf(\"can not slice %q\", astutil.ExprToString(op.Node.X))\n\t\t\treturn\n\t\t}\n\t\tstack.pushErr(xev.reslice(low, high, op.TrustLen))\n\t\treturn\n\tcase reflect.Map:\n\t\tif op.Node.High != nil {\n\t\t\tstack.err = errors.New(\"second slice argument must be empty for maps\")\n\t\t\treturn\n\t\t}\n\t\txev.mapSkip += int(low)\n\t\txev.mapIterator(0) // reads map length\n\t\tif int64(xev.mapSkip) >= xev.Len {\n\t\t\tstack.err = errors.New(\"map index out of bounds\")\n\t\t\treturn\n\t\t}\n\t\tstack.push(xev)\n\t\treturn\n\tcase reflect.Ptr:","sourceCodeStart":2255,"sourceCodeEnd":2291,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/eval.go#L2255-L2291","documentation":"Delve's expression evaluator (pkg/proc/eval.go) throws this when a slice expression x[low:high] is applied to a value of kind Slice, Array, or String whose base address (xev.Base) is 0. A zero base means the value has no backing memory — typically because it is nil or its storage could not be located. Delve refuses to fabricate an empty slice from a nonexistent base.","triggerScenarios":"Evaluating a slice expression in the debugger (CLI `print`, rpc2 Eval/Command, DAP evaluate) on a variable of slice/array/string type whose underlying data pointer is nil or whose Base could not be computed — e.g. `s[1:2]` where `s` is a nil slice, or slicing a string optimized into a register with no addressable backing store.","commonSituations":"Inspecting a slice field that was never initialized (nil slice), stepping through code before a slice is allocated, or slicing a variable the compiler kept in registers after inlining/optimization so Delve cannot resolve its data pointer.","solutions":["Check the sliced variable with `print s` first; if it is nil or unreadable, fix the program state or step past the allocation point before slicing.","Use `print s` with no slice bounds instead of slicing, to see the current state of the value.","If the variable is genuinely allocated, avoid optimized builds (`-gcflags='all=-N -l'` via `dlv debug`/`dlv exec`) so Delve can read the slice header from memory.","Re-enter the slice expression after the code path that assigns the slice has executed."],"exampleFix":"// before (at dlv prompt, s is a nil slice)\n(s) print s[0:2]\ncan not slice \"s[0:2]\"\n\n// after: check and allocate first, then slice\n(dlv) print s      // nil -> step until allocated\n(dlv) print s[0:2] // works once s points at real memory","handlingStrategy":"validation","validationCode":"// At the dlv prompt, before slicing:\n(dlv) print s           // confirm non-nil and readable\n// In program code:\nif s != nil && len(s) >= 2 { use(s[1:2]) }","typeGuard":"func sliceable(v interface{}) bool {\n    switch t := v.(type) {\n    case []int, []string, string, []byte:\n        _ = t\n        return true\n    }\n    return false\n}","tryCatchPattern":null,"preventionTips":["Print the variable before slicing to confirm it is allocated.","Debug unoptimized builds so slice headers are readable from memory.","Set breakpoints after slice allocation, not before."],"tags":["debugger","expression-evaluation","slice","nil-value"],"backgroundTag":"nil-slice-slice-operation","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}