{"record":{"id":"929825b4cdc1b1a3","repo":"go-delve/delve","slug":"expression-q-s-can-not-be-dereferenced","errorCode":null,"errorMessage":"expression %q (%s) can not be dereferenced","messagePattern":"expression %q \\((.+?)\\) can not be dereferenced","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/eval.go","lineNumber":2308,"sourceCode":"\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\n\tif len(xev.Children) == 1 {\n\t\t// this branch is here to support pointers constructed with typecasts from ints\n\t\txev.Children[0].OnlyAddr = false\n\t\tstack.push(&(xev.Children[0]))\n\t\treturn\n\t}\n\txev.loadPtr()\n\tif xev.Unreadable != nil {\n\t\tval, ok := constant.Uint64Val(xev.Value)\n\t\tif ok && val == 0 {","sourceCodeStart":2290,"sourceCodeEnd":2326,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/eval.go#L2290-L2326","documentation":"Thrown by evalPointerDeref when a dereference expression *x is evaluated but the operand's kind is not reflect.Ptr. Only pointer-typed values can be dereferenced; dereferencing an int, float, string, map, etc. is rejected with the operand's textual type included. This protects against treating arbitrary values as addresses.","triggerScenarios":"Evaluating `*x` in the debugger where x is not a pointer — e.g. `*count` where count is an int, `*s` where s is a string, or `*p` where p is a struct value rather than a pointer to one. Also occurs when the operand resolved to an interface's dynamic value that isn't a pointer.","commonSituations":"Habitual C-style coding in the dlv prompt on non-pointer variables, dereferencing the wrong variable after a rename, forgetting that a function returned a value (not a pointer), or an interface variable holding a non-pointer concrete value.","solutions":["Print the operand (`print x`) and confirm its type; only evaluate `*x` when x is a pointer.","If you need the value, drop the `*` — evaluate `x` directly.","If x is an interface wrapping a pointer, inspect `x` first; Delve usually shows the concrete value without explicit dereference.","Check the variable's declaration in the source to confirm it is `*T` not `T`."],"exampleFix":"// before (count is an int)\n(dlv) print *count\nexpression \"*count\" (int) can not be dereferenced\n\n// after\n(dlv) print count // plain value\n(dlv) print *countPtr // only when the operand is *T","handlingStrategy":"type-guard","validationCode":"// Before dereferencing at the prompt:\n(dlv) print x  // output shows the type; only *T values can be dereferenced","typeGuard":"func isPointer(v interface{}) bool {\n    return reflect.TypeOf(v).Kind() == reflect.Ptr\n}","tryCatchPattern":null,"preventionTips":["Verify the declaration is *T before writing *x in expressions.","Drop the `*` if you just want the value.","For interfaces, print the variable first — Delve shows the concrete value."],"tags":["debugger","expression-evaluation","pointer","type-mismatch"],"backgroundTag":"dereference-non-pointer","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}