{"record":{"id":"fecbc6b58751a7a7","repo":"go-delve/delve","slug":"can-not-slice-q-type-s","errorCode":null,"errorMessage":"can not slice %q (type %s)","messagePattern":"can not slice %q \\(type (.+?)\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/eval.go","lineNumber":2298,"sourceCode":"\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:\n\t\tif xev.Flags&VariableCPtr != 0 {\n\t\t\tstack.pushErr(xev.reslice(low, high, op.TrustLen))\n\t\t\treturn\n\t\t}\n\t\tfallthrough\n\tdefault:\n\t\tstack.err = fmt.Errorf(\"can not slice %q (type %s)\", astutil.ExprToString(op.Node.X), xev.TypeString())\n\t\treturn\n\t}\n}\n\n// Evaluates a pointer dereference expression: *<subexpr>\nfunc (scope *EvalScope) evalPointerDeref(op *evalop.PointerDeref, stack *evalStack) {\n\txev := stack.pop()\n\n\tif xev.Kind != reflect.Ptr {\n\t\tstack.err = fmt.Errorf(\"expression %q (%s) can not be dereferenced\", astutil.ExprToString(op.Node.X), xev.TypeString())\n\t\treturn\n\t}\n\n\tif xev == nilVariable {\n\t\tstack.err = errors.New(\"nil can not be dereferenced\")\n\t\treturn\n\t}\n","sourceCodeStart":2280,"sourceCodeEnd":2316,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/eval.go#L2280-L2316","documentation":"Thrown by evalop.Slice handling when the operand of a slice expression is not a sliceable kind (Slice, Array, String) and is not a C pointer (VariableCPtr). The evaluator falls through to the default case and reports the operand's Go type. It means slice syntax was applied to something intrinsically unsliceable, like an int, struct, map, or function.","triggerScenarios":"Evaluating `x[0:1]` where x has kind Int, Float, Bool, Struct, Map, Chan, Func, etc., or slicing a map with a [low:high] form (maps only support [k] indexing, not ranges). Also triggered by plain pointer arithmetic attempts unless the variable is flagged as a C pointer.","commonSituations":"Typo where the user meant to index instead of slice (`m[a:b]` on a map), slicing a numeric variable thinking it's a string, attempting C-style pointer slicing on a regular Go pointer (only C pointers created via cast get VariableCPtr), or confusion after a variable changed type.","solutions":["Print the operand (`print x`) and check its type in the error message; use the operation matching that type (indexing `[k]` for maps/arrays, slicing only for slice/array/string).","If you intended string/slice slicing, verify you are referencing the right variable name in this scope.","For Go pointers, dereference first (`*p`) then slice the result; raw pointer slicing is only supported for C pointers.","If the type is unexpected, check for shadowing or a type change (e.g. variable reassigned to a different type) in the current function."],"exampleFix":"// before (x is an int at dlv prompt)\n(dlv) print x[0:4]\ncan not slice \"x[0:4]\" (type int)\n\n// after: convert or index the correct object\n(dlv) print string(rune(x)) // or slice the actual string variable\n(dlv) print myString[0:4]","handlingStrategy":"validation","validationCode":"// Check operand type before applying slice syntax:\n(dlv) print x  // read the reported type from the output\n// Only use x[a:b] when the type is slice, array, or string.","typeGuard":"func isSliceable(v interface{}) bool {\n    switch reflect.TypeOf(v).Kind() {\n    case reflect.Slice, reflect.Array, reflect.String:\n        return true\n    }\n    return false\n}","tryCatchPattern":null,"preventionTips":["Prefer indexing [k] for maps and arrays-of-one; reserve [a:b] for slices/strings.","Re-read the variable's type in the error message and adjust the expression.","For pointer data, dereference before slicing unless it's a C pointer."],"tags":["debugger","expression-evaluation","type-mismatch","slice"],"backgroundTag":"invalid-type-operation","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}