{"record":{"id":"f0385bcb0bb6dea4","repo":"go-delve/delve","slug":"operator-s-can-not-be-applied-to-q","errorCode":null,"errorMessage":"operator %s can not be applied to %q","messagePattern":"operator (.+?) can not be applied to %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/eval.go","lineNumber":2410,"sourceCode":"\tr = constant.Compare(x, op, y)\n\treturn\n}\n\n// Evaluates expressions: -<subexpr> and +<subexpr>\nfunc (scope *EvalScope) evalUnary(op *evalop.Unary, stack *evalStack) {\n\txv := stack.pop()\n\n\txv.loadValue(loadSingleValue)\n\tif xv.Unreadable != nil {\n\t\tstack.err = xv.Unreadable\n\t\treturn\n\t}\n\tif xv.FloatSpecial != 0 {\n\t\tstack.err = errOperationOnSpecialFloat\n\t\treturn\n\t}\n\tif xv.Value == nil {\n\t\tstack.err = fmt.Errorf(\"operator %s can not be applied to %q\", op.Node.Op.String(), astutil.ExprToString(op.Node.X))\n\t\treturn\n\t}\n\trc, err := constantUnaryOp(op.Node.Op, xv.Value)\n\tif err != nil {\n\t\tstack.err = err\n\t\treturn\n\t}\n\tif xv.DwarfType != nil {\n\t\tr := xv.newVariable(\"\", 0, xv.DwarfType, scope.Mem)\n\t\tr.Value = rc\n\t\tstack.push(r)\n\t\treturn\n\t}\n\tstack.push(newConstant(rc, xv.bi, xv.mem))\n}\n\nfunc negotiateType(op token.Token, xv, yv *Variable) (godwarf.Type, error) {\n\tif xv == nilVariable {","sourceCodeStart":2392,"sourceCodeEnd":2428,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/eval.go#L2392-L2428","documentation":"Thrown by evalop.Unary handling: when the operand variable xv.Value is nil (its constant value could not be produced — the variable is unreadable, not a simple value, or its contents weren't loaded), applying a unary operator would panic inside constant.UnaryOp, so Delve pre-empts it with this descriptive error naming the operator and the operand expression.","triggerScenarios":"Evaluating `-x`, `!x`, `^x` where x is a variable whose Value field is nil — e.g. x is a struct/map/chan value with no scalar constant, a variable that failed to load (Unreadable), an optimized-out variable, or a value not materialized by the evaluator before the unary op runs.","commonSituations":"Negating a variable that was optimized out by the compiler, applying `!` to a non-bool composite value, or unary ops in breakpoint conditions on variables Delve couldn't read at the current stop point.","solutions":["Print the operand (`print x`) first; if unreadable/optimized-out, rebuild with `-gcflags='all=-N -l'` or step to a point where the variable is live.","Only apply unary operators to scalars: `-`/`^` on ints/floats, `!` on bools.","Re-enter the expression after the variable has been assigned so its value can be loaded.","If a breakpoint condition triggers it, simplify the condition to reference only live scalar variables."],"exampleFix":"// before (x is a struct / unreadable)\n(dlv) print -x\noperator - can not be applied to \"-x\"\n\n// after\n(dlv) print x.field // evaluate a numeric member first\n(dlv) print -x.field // negate the scalar","handlingStrategy":"validation","validationCode":"// Verify the operand loaded a value before unary ops:\n(dlv) print x        // if unreadable/optimized-out, fix build flags or location\n// only apply ! to bool, -/^ to numeric scalars","typeGuard":"func isScalar(v interface{}) bool {\n    k := reflect.TypeOf(v).Kind()\n    return (k >= reflect.Bool && k <= reflect.Complex128)\n}","tryCatchPattern":null,"preventionTips":["Print the operand before applying unary operators.","Rebuild unoptimized so variables are readable and live.","Simplify breakpoint conditions to reference only live scalars."],"tags":["debugger","expression-evaluation","unary-operator","nil-value"],"backgroundTag":"operator-unsupported-for-type","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}